Python selenium无法正常工作

时间:2016-05-24 19:52:42

标签: python selenium ubuntu firefox

我有一个简单的python脚本无效:

#!/usr/bin/env python

from selenium import webdriver


browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/')

但是当我尝试运行它时收到此错误:

Traceback (most recent call last):
  File "./test.py", line 5, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 103, in __init__
    self.binary, timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
    raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.

我正在运行selenium版本:

Name: selenium
Version: 2.53.2

Firefox版本:

ii  firefox-mozilla-build            14.0.1-0ubuntu1                  amd64        Mozilla Firefox, official Mozilla build, packaged for Ubuntu by the Ubuntuzilla project.

1 个答案:

答案 0 :(得分:0)

为了使用最新的selenium,你需要使用最新的firefox。你的firefox版本严重过时了。

然后,确保您可以从命令行打开Firefox。只需在终端中输入firefox即可。

最后,请确保更新python的selenium:sudo pip install -U selenium