selenium.common.exceptions.SessionNotCreatedException:消息:无法通过 Selenium 找到与 Firefox 46 匹配的一组功能 [英] selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities with Firefox 46 through Selenium

查看:31
本文介绍了selenium.common.exceptions.SessionNotCreatedException:消息:无法通过 Selenium 找到与 Firefox 46 匹配的一组功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里肯定有一些不匹配的版本,因为我无法通过 Python 使用 Selenium 来启动 Firefox 网络浏览器.我正在使用旧版本的 Firefox,因为这里的其他人使用相同的旧版本 Python,而对他们来说,旧版本的 Firefox 效果最佳.

I must have some versions here that don't match up since I can't get Selenium with Python to fire up a Firefox web browser. I'm using an older version of Firefox because other people in here have the same old version of Python and for them the old version of Firefox works best.

代码:

from selenium import webdriver
from selenium import common
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver=webdriver.Firefox(capabilities=DesiredCapabilities.FIREFOX)

错误:

Traceback (most recent call last):
  File "scrapeCommunitySelenium.py", line 13, in <module>
    driver=webdriver.Firefox(capabilities=DesiredCapabilities.FIREFOX)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__
    keep_alive=True)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
    self.error_handler.check_response(response)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

版本信息:

  • Python 2.7.10
  • 硒 3.8.0
  • 火狐 46.0
  • GeckoDriver 0.19.1(位于我的 PATH 环境变量中的文件夹中)
  • MacOS 10.12.6

推荐答案

当您使用 Selenium 3.8.0 时,您必须使用 GeckoDriver 作为必需项.但同样,当您使用 Firefox v46.0 时,您必须通过 DesiredCapabilities()ma​​rionette 设置为 False> 如下:

As you are using Selenium 3.8.0 you have to use GeckoDriver as a mandatory. But again as you are using Firefox v46.0 you have to set the capability marionette as False through DesiredCapabilities() as follows :

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
browser = webdriver.Firefox(capabilities=cap, executable_path="C:\path\to\geckodriver.exe")
browser.get('http://google.com/')
browser.quit()

这篇关于selenium.common.exceptions.SessionNotCreatedException:消息:无法通过 Selenium 找到与 Firefox 46 匹配的一组功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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