Selenium Firefox配置文件无法工作

4

我正在尝试加载我的Selenium火狐浏览器配置文件,但一直出现以下错误:

WebDriverException: Message: 无法加载配置文件。配置文件目录:%s 如果您在FirefoxBinary构造函数中指定了日志文件,请检查其中的详细信息。

15分钟前这段代码还能正常工作...我不确定发生了什么。

我的Firefox版本是43.0.4,Selenium版本是2.49。

这是导致错误的代码:

profile = webdriver.FirefoxProfile()
driver = webdriver.Firefox(profile)

我正在使用Windows 7专业版,Python 2.7.10 | Anaconda 2.3.0(64位)。

错误跟踪:

    Traceback (most recent call last):
  File "C:\Users\Moyp\dev\anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3035, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-15-37f7d14be053>", line 2, in <module>
    driver = webdriver.Firefox(profile)
  File "C:\Users\Moyp\dev\anaconda\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 77, in __init__
    RemoteWebDriver.__init__(self,
  File "C:\Users\Moyp\dev\anaconda\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 49, in __init__
    self.binary.launch_browser(self.profile)
  File "C:\Users\Moyp\dev\anaconda\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable()
  File "C:\Users\Moyp\dev\anaconda\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 103, in _wait_until_connectable
    raise WebDriverException("Can't load the profile. Profile "
WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.

已在MacOS上使用Selenium 2.49和Firefox 43.0.4测试了Python 2.7和Python 3.5,没有出现错误。您能否分享更多有关您的设置、执行的代码和完整的回溯信息? - alecxe
1
我刚刚添加了更多细节,我执行的代码就是我发布的那两行。 - collarblind
刚刚更新了回溯信息,之前的是错误的。 - collarblind
快速检查一下:您能否在IPython终端中导入selenium并打印出selenium.__version__?谢谢。 - alecxe
1
它说是“2.46.1”,我刚刚重新启动了PyCharm,现在它显示为“2.49”,代码现在可以工作了。谢谢! - collarblind
好的,已经发布为答案来解决这个话题。谢谢。 - alecxe
3个回答

4
不同的Selenium版本与某些Firefox版本存在兼容性问题。Selenium 2.49和Firefox 43配合良好。
确保您真正使用的是"Selenium 2.49":
import selenium
print(selenium.__version__) 

2

有一些与个人档案相关的已知问题。根据Selenium发行说明,您不应再使用profile = webdriver.FirefoxProfile(profilepath)...


2

我曾经遇到过类似的问题,问题出在启动虚拟显示器后没有停止它,所以所有的都在后台运行。运行 top 命令并检查测试完成后是否有浏览器 firefox 在运行。


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