【问题标题】:selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities with Firefox 46 through Seleniumselenium.common.exceptions.SessionNotCreatedException:消息:无法通过 Selenium 找到与 Firefox 46 匹配的一组功能
【发布时间】:2018-05-26 17:32:03
【问题描述】:

我这里肯定有一些不匹配的版本,因为我无法让 Selenium 与 Python 一起启动 Firefox 网络浏览器。我使用的是旧版本的 Firefox,因为这里的其他人使用相同的旧版本 Python,并且对他们来说旧版本的 Firefox 效果最好。

代码:

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

【问题讨论】:

  • 是在网格上运行还是在本地运行?
  • 在本地运行。

标签: python selenium firefox selenium-webdriver geckodriver


【解决方案1】:

这个错误也可能来自32bits版本,请选择x64版本修复。

【讨论】:

    【解决方案2】:

    当您使用 Selenium 3.8.0 时,您必须强制使用 GeckoDriver。但是,当您使用 Firefox v46.0 时,您必须将功能 ma​​rionette 设置为 FalseDesiredCapabilities(),如下所示:

    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()
    

    【讨论】:

    • ' cap["marionette"] = false ' => 给出错误:'caps not defined'。这条线有什么变化?
    • 我不断收到“浏览器似乎在我们重新连接之前已经退出。”但是,每次我运行它时它都会要求关闭浏览器。
    • 此方案也适用于MacOS,只需更改可执行路径即可。
    【解决方案3】:

    该错误有一些可能的原因,例如:

    1. Firefox 已安装在您的系统中
    2. Firefox 访问权限仅限管理员
    3. Firefox 未安装同名
    4. Firefox 版本未更新

    【讨论】:

      【解决方案4】:

      我在我的 MacOS 10.5 Catalina 上遇到了这个问题。 我做了什么: 1.使用brew install geckodriver安装geckodriver 2.删除/卸载我现有的(旧)Firefox浏览器(v.46)并安装v70。 3. 试过了:

      from selenium import webdriver
      browser = webdriver.Firefox()
      browser.get('http://google.com')
      

      通过启动 Firefox 并加载 google.com,以上操作正常,没有错误

      【讨论】:

        【解决方案5】:

        您也可以在 Chrome 上看到类似的错误。如果您在 Ubuntu 上看到它,原因可能是您预装了较旧的 Chrome 和 Firefox 版本。并且您已经下载了最新版本的 Chrome/Firefox 驱动程序。

        简单的解决方案是:

        1. 卸载现有的Ubuntu提供的Chrome/Firefox浏览器:进入应用程序(左上角)->Ubuntu软件中心->搜索Chrome并卸载。
        2. 安装最新的浏览器。

        对于 Chrome,步骤如下:

        1. wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

        2. sudo dpkg -i google-chrome-stable_current_amd64.deb

        完成!

        【讨论】:

          【解决方案6】:

          我收到此错误是因为我的机器上没有安装 Firefox 浏览器。您可以下载Firefox或下载Chrome驱动程序here。如果您使用 Chrome 驱动器,请确保将其添加到路径中(就像 geckodriver 一样)。

          你可以像这样使用它:

          from selenium import webdriver
          
          driver = webdriver.Chrome()
          driver.get("http://www.python.org")
          

          【讨论】:

          • 这里一样!哇,在遇到这个之前,我一定已经阅读了超过 75 个网页......
          【解决方案7】:

          如果您要使用 Geckodriver,您肯定需要使用更新版本的 Firefox。 Frex:https://github.com/mozilla/geckodriver/releases/tag/v0.19.0 列出 FF55 或更高版本。

          如果您打算使用 FF46,请不要使用 geckodriver。更新您的能力以将 Marionette 设置为 False:

          caps = DesiredCapabilities.FIREFOX.copy()
          caps['marionette'] = False
          driver=webdriver.Firefox(capabilities=caps)
          

          【讨论】:

          • 将 marionette 设置为 False 似乎可以解决问题。谢谢!
          猜你喜欢
          • 2019-01-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-12-31
          • 2017-11-30
          • 2018-09-22
          • 1970-01-01
          相关资源
          最近更新 更多