无法在python中的selenium webdriver中加载firefox

时间:2017-08-15 12:13:09

标签: python selenium firefox selenium-webdriver geckodriver

我已经在Windows 7上安装了Python 3.6.2,Selenium 3.5.0和GeckoDriver 0.18.0以及firefox版本54.0.1version。我正在尝试运行一个selenium脚本,它正在加载一个我遇到不匹配的firefox firefox版本错误。请告诉我这是什么问题。下面的代码和错误消息。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities["marionette"] = False
binary = FirefoxBinary('C:/Users/gopalakrishnarr/Downloads/FirefoxPortable/App/Firefox/firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, capabilities=capabilities, executable_path="C:/Users/gopalakrishnarr/AppData/Local/Programs/geckodriver-v0.18.0-win64/geckodriver.exe")
driver.get("http://www.google.com")

返回错误消息:

Traceback (most recent call last):
  File "C:\PythonSelenium\Sample.py", line 12, in <module>
    driver = webdriver.Firefox(firefox_binary=binary, capabilities=capabilities, executable_path="C:/Users/gopalakrishnarr/AppData/Local/Programs/geckodriver-v0.18.0-win64/geckodriver.exe")
  File "C:\Users\gopalakrishnarr\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium-3.5.0-py3.6.egg\selenium\webdriver\firefox\webdriver.py", line 171, in __init__
    self.binary, timeout)
  File "C:\Users\gopalakrishnarr\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium-3.5.0-py3.6.egg\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Users\gopalakrishnarr\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium-3.5.0-py3.6.egg\selenium\webdriver\firefox\firefox_binary.py", line 73, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "C:\Users\gopalakrishnarr\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium-3.5.0-py3.6.egg\selenium\webdriver\firefox\firefox_binary.py", line 114, in _wait_until_connectable
    % (self.profile.path))

selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: C:\Users\GOPALA~1\AppData\Local\Temp\tmpc1dfsd6w If you specified a log_file in the FirefoxBinary constructor, check it for details.

1 个答案:

答案 0 :(得分:6)

使用Python 3.6.2Selenium 3.5.0 GeckoDriver 0.18.0且Firefox浏览器版本54.0.1 Windows 7时,您无法设置属性{ {1}}到marionette。将False强制设置为marionette会提升False。因此,您必须接受默认设置 WebDriverException ,或者您可以明确将 ["marionette"] = True 设置为 ["marionette"] 如下:

True