SessionNotCreatedException:消息:预期的浏览器二进制位置,但无法在默认位置找到二进制文件,没有“moz:firefoxOptions.binary" [英] SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary'

查看:25
本文介绍了SessionNotCreatedException:消息:预期的浏览器二进制位置,但无法在默认位置找到二进制文件,没有“moz:firefoxOptions.binary"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I try to create a Firefox instance in Selenium, I get the following error:

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 上运行
任何建议将不胜感激.

I'm running on Ubuntu 20.04
Any suggestions would be appreciated .

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 浏览器 会话)时无法找到 firefox 二进制文件.

...implies that the GeckoDriver was unable to locate the firefox binary while trying to initiate/spawn a new Browsing Context i.e. Firefox Browser session.

此错误的可能原因可能是以下之一:

The probable reason for this error can be either of the following:

  • Firefox 未安装在您的系统中.
  • Firefox 未安装在您系统中的默认位置.
  • Firefox isn't installed in your system.
  • Firefox isn't installed in the default location within your system.

可能的解决方案是:

  • 如果您的系统中没有安装 Firefox,您需要在执行测试之前安装它.

  • If Firefox isn't installed in your system, you need to install it before executing your tests.

如果 Firefox 安装在自定义位置,则需要通过以下方式传递 firefox 二进制文件的绝对路径一个 Options() 实例:

If Firefox is installed at a customized location, you need to pass the absolute path of the firefox binary as follows through an Options() instance:

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/')

您可以在以下位置找到一些相关的详细讨论:

You can find a couple of relevant detailed discussion in:

这篇关于SessionNotCreatedException:消息:预期的浏览器二进制位置,但无法在默认位置找到二进制文件,没有“moz:firefoxOptions.binary"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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