Selenium Firefox Profile无法正常工作

时间:2016-01-14 16:38:04

标签: python firefox selenium

我正在尝试加载我的selenium 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.

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

我有firefox 43.0.4和selenium 2.49

这是我抛出错误的代码:

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

我正在使用Windows 7 Professional,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.

3 个答案:

答案 0 :(得分:4)

不同的selenium版本与某些Firefox版本存在兼容性问题。 Selenium 2.49和Firefox 43很好地协同工作。

确保您确实使用selenium 2.49

import selenium
print(selenium.__version__) 

答案 1 :(得分:2)

我有类似的问题,问题是在开始无头的虚拟显示后我没有停止它。所以他们都在后台运行。运行top命令,检查测试完成后是否没有运行浏览器firefox

答案 2 :(得分:2)

个人资料中存在一些已知问题。根据Selenium发行说明,您不应再使用profile = webdriver.FirefoxProfile(profilepath) ...