WebDriverException:消息:无法加载配置文件。不知道发生了什么

时间:2016-08-21 02:26:45

标签: python selenium firefox

我已经使用webdriver.Firefox()多年了,今天我开始了另一个项目并且browser = webdriver.Firefox()正在返回

WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.

我尝试将C:\Program Files (x86)\Mozilla Firefox\firefox.exe添加到我的PATH中。我试过了pip install -U selenium。我试过了

binary = FirefoxBinary('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe')
browser = webdriver.Firefox(firefox_binary=binary)

profile = FirefoxProfile("C:\Users\Me\AppData\Roaming\Mozilla\Firefox\Profiles\8u2w2ge1.Me")
browser = webdriver.Firefox(profile)

我在我的firefox插件中添加了addon checkcompatibility。没什么,什么都没有,同样的错误,Python 2.7.11,Windows 10 x64

这是我得到的一般追溯。

Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
    browser = webdriver.Firefox(firefox_binary=binary)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 108, in _wait_until_connectable
    % (self.profile.path))
WebDriverException: Message: Can't load the profile. Profile Dir: c:\users\me\appdata\local\temp\tmpwvgny8 If you specified a log_file in the FirefoxBinary constructor, check it for details.

任何人都知道为什么在temp目录中创建此配置文件时遇到问题?一种新方法强制它存在于存在的配置文件中,因为我的旧方法不起作用。

1 个答案:

答案 0 :(得分:0)

我实际上找到了一个解决这个问题的方法,它并不完美,我实际上是通过chromedriver使用chrome,因为它更稳定一些,但是使用firefox你可能想要下载一个geckodriver并将其包含在您的系统路径或浏览器设置中的路径https://github.com/mozilla/geckodriver/releases,似乎是他们保留版本的地方,chrome有一个chromedriver,其功能和使用方式大致相同。我不确定为什么我们需要这些新的驱动程序在windows中使用selenium,但这就是生活,希望这能为其他人节省一些工作。