Python: Selenium Firefox Webdriver出现错误:'无法加载配置文件...WARN addons.xpi...'

27

我正试图运行以下Python代码,通过Selenium创建一个Firefox Webdriver窗口:

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.google.com")

虽然这段代码几周前运行良好,但现在会产生以下不祥的消息:

 Traceback (most recent call last):
  File "test.py", line 2, in <module>
    driver = webdriver.Firefox()
  File "c:\python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 60, in __init__
    self.binary, timeout),
  File "c:\python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
    self.binary.launch_browser(self.profile)
  File "c:\python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 61, in launch_browser
    self._wait_until_connectable()
  File "c:\python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 105, in _wait_until_connectable
    self.profile.path, self._get_firefox_output()))
selenium.common.exceptions.WebDriverException: Message: 'Can\'t load the profile. Profile Dir: c:\\users\\douglas\\appdata\\local\\temp\\tmpuf4ipq Firefox output: *** LOG addons.xpi: startup\r\n*** WARN addons.xpi: Ignoring missing add-on in C:\\Program Files\\CheckPoint\\ZAForceField\\WOW64\\TrustChecker\r\n*** WARN addons.xpi: Ignoring missing add-on in C:\\ProgramData\\Norton\\{78CA3BF0-9C3B-40e1-B46D-38C877EF059A}\\NSM_2.9.5.20\\coFFFw\r\n*** LOG addons.xpi: Skipping unavailable install location app-system-local\r\n*** LOG addons.xpi: Skipping unavailable install location app-system-share\r\n*** LOG addons.xpi: checkForChanges\r\n*** LOG addons.xpi: No changes found\r\n*** Blocklist::_loadBlocklistFromFile: blocklist is disabled\r\n************************************************************\r\n* Call to xpconnect wrapped JSObject produced this error:  *\r\n[Exception... "\'[JavaScript Error: "this._defaultEngine is null" {file: "resource://gre/components/nsSearchService.js" line: 3527}]\' when calling method: [nsIBrowserSearchService::currentEngine]"  nsresult: "0x80570021 (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)"  location: "JS frame :: chrome://browser/content/search/search.xml :: get_currentEngine :: line 130"  data: yes]\r\n************************************************************\r\n************************************************************\r\n* Call to xpconnect wrapped JSObject produced this error:  *\r\n[Exception... "\'[JavaScript Error: "this._defaultEngine is null" {file: "resource://gre/components/nsSearchService.js" line: 3527}]\' when calling method: [nsIBrowserSearchService::currentEngine]"  nsresult: "0x80570021 (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)"  location: "JS frame :: chrome://browser/content/search/search.xml :: get_currentEngine :: line 130"  data: yes]\r\n************************************************************\r\n************************************************************\r\n* Call to xpconnect wrapped JSObject produced this error:  *\r\n[Exception... "\'[JavaScript Error: "this._defaultEngine is null" {file: "resource://gre/components/nsSearchService.js" line: 3527}]\' when calling method: [nsIBrowserSearchService::currentEngine]"  nsresult: "0x80570021 (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)"  location: "JS frame :: resource://app/components/nsBrowserGlue.js :: <TOP_LEVEL> :: line 354"  data: yes]\r\n************************************************************\r\n************************************************************\r\n* Call to xpconnect wrapped JSObject produced this error:  *\r\n[Exception... "\'[JavaScript Error: "this._defaultEngine is null" {file: "resource://gre/components/nsSearchService.js" line: 3527}]\' when calling method: [nsIBrowserSearchService::currentEngine]"  nsresult: "0x80570021 (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)"  location: "JS frame :: resource://app/components/nsBrowserGlue.js :: <TOP_LEVEL> :: line 354"  data: yes]\r\n************************************************************\r\n'

有人知道这是什么意思吗?或者我该怎么做才能解决错误并使代码按预期运行?我通过谷歌搜索找到了相关的错误消息,但没有任何东西可以让我解决这个问题。值得一提的是,我可以通过将上述第二行更改为driver = webdriver.Chrome()而无问题地打开Chrome Webdriver。我正在使用Python 2.7、Selenium 2.35.0(我刚刚运行了“pip install selenium --upgrade”)和Windows 8机器上的Firefox 26.0。任何其他人可以提供的提示或建议都将不胜感激。

一个与本题略有不同但非常有用的关于如何防止Selenium创建临时Firefox配置文件的问题最终对我帮助很大,也为下一个来到这里的人提供了一些价值。 - slushy
5个回答

29

Selenium 2.35不兼容Firefox 26。根据发行说明,在Selenium 2.39中添加了对FF 26的支持。您需要升级到2.39版。请尝试pip install -U selenium


4
我运行了pip install -U selenium命令,看起来selenium已经升级了,但我仍然收到相同的错误消息。欢迎提出其他建议。 - duhaime
你发的追踪信息(trace)不是你发的代码示例(code sample)产生的。你的机器上是否安装了多个Python版本?你确定你仍然得到的是“相同”的错误而不是“类似”的错误吗? - Silas Ray
非常感谢,@Silas Ray;我刚刚更新了上面发布的代码生成的错误信息。我相信这台机器上只有2.7版本。再次感谢您的帮助。 - duhaime
看起来由于某些原因无法加载用户配置文件。它还在抱怨一堆缺失/不兼容的Firefox插件,但这些都是警告。你没有尝试使用自定义配置文件吧? - Silas Ray
2
webdriver.xpi位于Selenium软件包分发的site-packages中。每次创建Firefox实例时,它都会被复制到一个临时目录中,然后在启动浏览器时加载到浏览器中。使用pip更新selenium应该已经更新了xpi文件(实际上是驱动Selenium在浏览器中执行操作的Firefox插件),当您使用webdriver.Firefox()实例化时启动。Firefox配置文件是不同的,但与此相关,因为它们定义要加载哪些插件,并且Selenium将Selenium插件添加到它使用的动态复制配置文件列表中。 - Silas Ray
显示剩余3条评论

0

我刚刚在使用FF36和selenium 2.44.0时遇到了同样的问题。重新安装FF 32.0解决了这个问题。


0

我在Win8.1 FF28和Python3.4/Selenium 2.41中也遇到了这个问题。但是当我将FF降级到24时,它就可以工作了!我还在Win8.1/FF27/Python3.4/Selenium 2.41中进行了测试,也可以正常工作。


0

不确定它在Windows上是否也能正常工作,但对于我来说,Firefox 26和selenium 2.37.0的组合运行良好。


0

我在我的Kubuntu 14.04桌面上遇到了同样的问题,我卸载了Firefox 47.XX并重新安装了Firefox 45.XX,问题得到了解决。

下载Firefox Debian软件包

  • apt-get purge firefox
  • dpkg -i firefox-XXXXXXXXXX.deb

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接