当前位置: 首页 > 面试题库 >

selenium.common.exceptions.SessionNotCreatedException:消息:无法通过Selenium找到与Firefox 46匹配的功能集

邵星光
2023-03-14
问题内容

我这里必须有一些版本不匹配,因为我无法使用Python来实现Selenium来启动Firefox
Web浏览器。我使用的是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
  • selenium3.8.0
  • Firefox 46.0
  • GeckoDriver 0.19.1(位于我的PATH环境变量中的文件夹中)
  • MacOS 10.12.6

问题答案:

使用 Selenium 3.8.0时 ,必须将 GeckoDriver 用作必需项。但同样由于您使用 的Firefox v46.0
你必须设置能力 的提线木偶False经过DesiredCapabilities()如下:

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


 类似资料: