gpt4 book ai didi

python - SessionNotCreatedException : Message: Expected browser binary location, 但无法在默认位置找到二进制文件,没有 'moz:firefoxOptions.binary'

转载 作者:行者123 更新时间:2023-12-04 11:22:30 26 4
gpt4 key购买 nike

当我尝试在 Selenium 中创建 Firefox 实例时,出现以下错误:

Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line 
我在 Ubuntu 20.04 上运行
任何建议,将不胜感激 。
browser = webdriver.Firefox()

Traceback (most recent call last):
File "key.py", line 10, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

最佳答案

这个错误信息...

selenium.common.exceptions.SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
...暗示 GeckoDriver在尝试启动/生成新的浏览上下文(即 Firefox 浏览器 session )时无法找到 Firefox 二进制文件。

原因
此错误的可能原因可能是以下任一原因:
  • 您的系统中未安装 Firefox。
  • Firefox 未安装在您系统中的默认位置。

  • 解决方案
    可能的解决方案是:
  • 如果您的系统中没有安装 Firefox,您需要在执行测试之前安装它。
  • 如果 Firefox 安装在自定义位置,则需要通过 Options() 传递 Firefox 二进制文件的绝对路径,如下所示。实例:
    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options

    options = Options()
    options.binary_location = r"C:/location/to/Firefox/Binary/firefox.exe"
    driver = webdriver.Firefox(options=options, executable_path="C:/location/to/geckodriver.exe")
    driver.get('http://google.com/')

  • 引用
    您可以在以下位置找到一些相关的详细讨论:
  • InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python
  • Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided
  • Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided using GeckoDriver
  • 关于python - SessionNotCreatedException : Message: Expected browser binary location, 但无法在默认位置找到二进制文件,没有 'moz:firefoxOptions.binary',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64908154/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com