【问题标题】:Python selenium web driver example from django docs error: 'f.QueryInterface is not a function'来自 django docs 错误的 Python selenium Web 驱动程序示例:'f.QueryInterface 不是函数'
【发布时间】:2014-07-23 13:03:25
【问题描述】:

我想为 Django 应用程序编写一些 Selenium 单元测试。我们已经有很多常规的 python 单元测试。我已经复制了example selenium test from the Django docs(这只不过是硒的“hello world”):

from selenium.webdriver.firefox.webdriver import WebDriver
from django.test import LiveServerTestCase


class MySeleniumTestCase(LiveServerTestCase):
    @classmethod
    def setUpClass(cls):
        cls.selenium = WebDriver()
        super(MySeleniumTestCase, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        cls.selenium.quit()
        super(MySeleniumTestCase, cls).tearDownClass()

    def test_simple(self):
        self.selenium.get("/")

但是,当我在本地运行此程序或使用 CircleCI (tests-in-the-cloud-as-a-service) 时,我收到此错误:

======================================================================
ERROR: test_simple (proj.lib.tests.MySeleniumTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu//proj/proj/lib/tests.py", line 1347, in test_simple
    self.selenium.get("/")
  File "/home/ubuntu/proj/venv/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 185, in get
    self.execute(Command.GET, {'url': url})
  File "/home/ubuntu/proj/venv/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 173, in execute
    self.error_handler.check_response(response)
  File "/home/ubuntu/proj/venv/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 164, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: u'f.QueryInterface is not a function' ; Stacktrace: 
    at FirefoxDriver.prototype.get (file:///tmp/tmpXXrLF6/extensions/fxdriver@googlecode.com/components/driver_component.js:9333)
    at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpXXrLF6/extensions/fxdriver@googlecode.com/components/command_processor.js:11455)
    at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpXXrLF6/extensions/fxdriver@googlecode.com/components/command_processor.js:11460)
    at DelayedCommand.prototype.execute/< (file:///tmp/tmpXXrLF6/extensions/fxdriver@googlecode.com/components/command_processor.js:11402)

这是 Django 1.5.5、python 2.7、selenium python 包 2.42.1

有什么问题?如何让硒发挥作用?

【问题讨论】:

  • 你用的是什么版本的火狐?

标签: python django testing selenium circleci


【解决方案1】:

get 方法需要完整的 URL。即包含协议和主机名/ip的URI。

self.selenium.get("/")
# becomes
self.selenium.get("http://stackoverflow.com/questions/24011019/")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2023-01-30
    相关资源
    最近更新 更多