selenium.common.异常.SessionNotCreatedException:消息:找不到与GeckoDriver、Selenium和Firefox匹配的功能集

2024-04-19 23:40:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我用firefoxwebdriver开发了一个使用selenium的python脚本。它在我的机器里工作正常。但是如果我在另一台机器上执行相同的脚本,它会给出以下错误。在

Traceback (most recent call last):
  File "insurance_web_monitor.py", line 13, in <module>
    driver = Firefox(executable_path='geckodriver', firefox_options=options)
  File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py",
line 167, in __init__
    keep_alive=True)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 251, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 320, in execute
    self.error_handler.check_response(response)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py"
, line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a
 matching set of capabilities

这是我的密码

^{pr2}$

我机器的配置是

Windows => 7 Professional 64-bit
Python => 3.4.4
Selenium => 3.14
Firefox => 61.0.2
geckodriver => 0.21.0

其他机器的配置是

Windows => 7 Professional 64-bit
Python => 3.4.4
Selenium => 3.14
Firefox => 61.0.2
geckodriver => 0.21.0

是的,每个配置都是完全相同的。虽然这看起来很傻,但它不起作用,它折磨着我。 我在机器之间有什么需要考虑的吗? 提前谢谢。在


Tags: inpy机器remoteresponselibpackagesselenium
1条回答
网友
1楼 · 发布于 2024-04-19 23:40:13

根据您使用以下测试配置的问题和代码块:

  • 硒=3.14
  • 壁虎河=>;0.21.0
  • 火狐浏览器=>61.0.2

你必须强制使用木偶技能。为了达到这一目的:

  • 您可以让这个功能保持不变,因为默认情况下,marionette设置为True。在
  • 您还可以指定功能木偶,如下所示:

    cap = DesiredCapabilities().FIREFOX
    cap["marionette"] = True
    

本用例

此错误消息。。。在

^{pr2}$

…这意味着GeckoDriver无法启动/产生新的WebBrowser,即Firefox浏览器会话。在

您看到的错误背后有许多可能性,可以通过以下任一步骤解决:

  • 当您在Windows操作系统上运行时,您需要传递可执行路径以及包含以下内容的

    • 壁虎的绝对路径。在
    • GeckoDriver绝对路径应该通过单引号和单反斜杠以及raw(r)开关来提及。在
    • 包括GeckoDriver二进制文件的扩展。在
    • 您的代码行将是:

      driver = Firefox(executable_path=r'C:\path\to\geckodriver.exe', firefox_options=options, capabilities=cap)
      

参考文献

相关问题 更多 >