为了进行研究,我在firefox中做了一些源代码修改,然后自己构建。为了自动化测试,我选择使用Selenium,但不幸的是,我新建的Firefox似乎不支持Selenium。
我做了以下事情:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary("/path/to/firefox/binary")
d = webdriver.Firefox(firefox_binary=binary)
d.get("http://www.google.de")
Firefox确实打开并响应(我可以在搜索栏中输入网站)。但是过了一会儿,python脚本崩溃并显示以下错误消息:
Traceback (most recent call last):
File "firefox.py", line 7, in <module>
d = webdriver.Firefox(firefox_binary=binary)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 109, in _wait_until_connectable
raise WebDriverException("Can't load the profile. Profile "
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.
我在Google上搜索了该错误消息,并提出了大多数解决方案,我应该更新Selenium,因为它不支持所使用的Firefox版本。不幸的是,我安装了最新版本的Selenium(2.44.0),甚至使用了旧版本的Firefox(版本33)来排除这一点。
我还通过构建干净,未修改的Firefox确保我的代码修改不是导致崩溃的原因。 Selenium也不适用于此Firefox。
如果我不指定firefox二进制文件,而让Selenium使用已安装的Firefox,则一切正常。所以我的猜测是,firefox构建出了点问题,正如我在在线文档(例如./mach构建)中提到的那样。
有谁知道,我的错误可能是什么?任何帮助是极大的赞赏!
一些设置信息:
最佳答案
Ubuntu 14.04,Firefox 36.0, Selenium 2.44.0。
相同的问题通过以下方法解决:
sudo pip install -U selenium
使用FF36可以使用 Selenium 2.45.0。
更新:Selenium 2.53+与FF45兼容
您可以获取较旧的FF版本here