【问题标题】:Selenium WebDriver PYTHON selenium.common.exceptions.WebDriverException:Selenium WebDriver PYTHON selenium.common.exceptions.WebDriverException:
【发布时间】:2014-04-17 11:49:24
【问题描述】:

这是我的代码:

 from selenium import webdriver
 from selenium.webdriver.common.keys import Keys

 browser = webdriver.Firefox()

 browser.get('http://www.yahoo.com')
 assert 'Yahoo!' in browser.title

 elem = browser.find_element_by_name('p')  # Find the search box
 elem.send_keys('seleniumhq' + Keys.RETURN)

 browser.quit()

但是我得到了一个错误:

        root@debian:~# python python_org_search.py
        Traceback (most recent call last):
          File "python_org_search.py", line 4, in <module>
            browser = webdriver.Firefox()
          File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
            self.binary, timeout),
          File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
            self.binary.launch_browser(self.profile)
          File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 61, in launch_browser
            self._wait_until_connectable()
          File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable
            self._get_firefox_output())
        selenium.common.exceptions.WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'

这个错误是因为我使用的是 CLI(命令行界面)操作系统(DEBIAN 服务器 6.0.1)

【问题讨论】:

  • 感谢@fiskerXO 的编辑
  • 欢迎。你安装了哪个版本的 Selenium?
  • 你能把你在终端输入时得到的结果贴出来吗:which firefox
  • @Tweek 通常会在浏览器终端出现同样的错误。但是作者可以透露终端代码。
  • @Tweek 和 fiskerXO 感谢 cmets.. root@debian:~# which firefox /usr/bin/firefox

标签: python selenium selenium-webdriver debian automated-tests


【解决方案1】:

大多数浏览器需要在 x 显示器中运行。我通过运行 xvfb (apt-get install xvfb) 解决了这个问题。

那么python需要能够使用这个显示:https://pypi.python.org/pypi/PyVirtualDisplay

启动显示,然后初始化 webdriver 浏览器并测试...

【讨论】:

  • 是的,它使用 PyVirtualDisplay 完成,代码运行完美..但是当测试通过时只有一件事它没有显示任何内容,如果它有错误,那么它会向我显示一条消息,如 ASSERTIONERROR.. 怎么能我得到它就像 10 次测试通过或测试失败。或者一些难以理解的东西
  • 您需要使用测试运行器。标准库中有一个叫做 unittest。
猜你喜欢
  • 2022-01-21
  • 2021-06-08
  • 2014-11-15
  • 1970-01-01
  • 2013-04-04
  • 2021-07-12
  • 2015-05-18
  • 2017-04-11
  • 1970-01-01
相关资源
最近更新 更多