无法在python的硒Webdriver中加载Firefox [英] Unable to load firefox in selenium webdriver in python

查看:124
本文介绍了无法在python的硒Webdriver中加载Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Windows 7上安装了带有GeckoDriver 0.18.0的Python 3.6.2,Selenium 3.5.0,并且firefox版本是54.0.1version.我正在尝试运行一个硒脚本,该脚本正在加载与我不匹配的firefox. Firefox版本错误.请让我知道是什么问题.下面的代码和错误消息.

I have installed Python 3.6.2, Selenium 3.5.0 with GeckoDriver 0.18.0 and the firefox version is 54.0.1version on windows 7. I am trying to run a selenium script which is loading a firefox where i get mismatch with firefox version error. Please let me know what is the issue. The code and error message below.

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.

推荐答案

使用Python 3.6.2Selenium 3.5.0GeckoDriver 0.18.0且Firefox浏览器版本在Windows 7上是54.0.1时,您将无法将属性marionette设置为False.强制将marionette设置为False将引发WebDriverException.因此,您要么必须接受默认设置 ["marionette"] = True ,要么可以将 ["marionette"] 显式设置为 True ,如下所示:

When you work with Python 3.6.2, Selenium 3.5.0 with GeckoDriver 0.18.0 and the Firefox browser version is 54.0.1 on Windows 7, you can't set the property marionette to False. Forcefully setting marionette to False will raise an WebDriverException. So either you have to accept the default setting of ["marionette"] = True or you can explicitly set ["marionette"] to True as follows:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities["marionette"] = True
binary = FirefoxBinary('C:/Program Files/Mozilla Firefox/firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, capabilities=capabilities, executable_path="C:/Utility/BrowserDrivers/geckodriver.exe")
driver.get("http://www.google.com")

这篇关于无法在python的硒Webdriver中加载Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆