Firefox selenium 驱动程序似乎正在崩溃(也许是因为我使用的是 Firefox-beta ppa?):
>>> from selenium import webdriver
>>> webdriver.Firefox
<class 'selenium.webdriver.firefox.webdriver.WebDriver'>
>>> webdriver.Firefox()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, 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.
因此我尝试安装 Chromium 驱动程序但 Selenium 仍然失败:
>>> webdriver.Chrome()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 59, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/service.py", line 66, in start
"ChromeDriver executable needs to be available in the path. "
selenium.common.exceptions.WebDriverException: Message: ChromeDriver executable needs to be available in the path. Please download from http://chromedriver.storage.googleapis.com/index.html and read up at http://code.google.com/p/selenium/wiki/ChromeDriver
是我遗漏了什么还是这个包完全坏了?如果这很重要的话,我安装了 Chromium 和 Google Chrome 进行测试。
答案1
Firefox webdriver 失败并显示以下消息:
“浏览器似乎在我们连接之前已退出”
这意味着 selenium 成功找到了它。我还认为 beta 版本可能是根本原因,因为对于我来说,使用 repo 版本就可以开箱即用。
对于 Chromium,您必须安装以下软件包:
sudo apt-get install python-selenium chromium-chromedriver
并修复
libui_base.so
库路径(参见Ubuntu 14.04 上的 Chromedriver - 加载共享库时出错:libui_base.so)使用 Chrome网络驱动程序安装以下依赖项:
sudo apt-get install python-selenium
并从以下位置下载 Chromedriver这里,选择与您的体系结构相对应的一个,例如:
http://chromedriver.storage.googleapis.com/2.14/chromedriver_linux64.zip 或者http://chromedriver.storage.googleapis.com/2.14/chromedriver_linux32.zip
chromedriver
例如,在您的文件夹中提取文件$HOME
。然后从 python 启动 chromedriver,打开终端并输入:
$ python Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> from selenium import webdriver >>> driver = webdriver.Chrome(os.path.expanduser('~/chromedriver'))
最后,我建议使用python-selenium
Ubuntu 存储库提供的软件包版本,以避免安装/usr/local/lib
。