【问题标题】:System.InvalidOperationException: 'Expected browser binary location, but unable to find binary in default location error using Firefox Selenium in C#System.InvalidOperationException: '预期的浏览器二进制位置,但在 C# 中使用 Firefox Selenium 时无法在默认位置找到二进制错误
【发布时间】:2020-11-04 23:43:22
【问题描述】:

我正在尝试在 C# 中使用 Selenium,但出现以下错误,

System.InvalidOperationException: '预期的浏览器二进制位置, 但无法在默认位置找到二进制文件,没有 提供了“moz:firefoxOptions.binary”功能,但没有二进制标志 在命令行上设置(SessionNotCreated)'

会是什么?

【问题讨论】:

标签: c# selenium selenium-webdriver firefox selenium-firefoxdriver


【解决方案1】:

您需要下载 Mozilla Firefox

https://www.mozilla.org/en-US/firefox/new/

然后安装 Mozilla Firefox。

【讨论】:

  • 我下载 selenium firefox ,我想用 selenium 打开 tor
  • 您是否在默认位置安装了 Firefox?
  • 我的桌面上有 Tor 浏览器。是的,我有 Firefox
【解决方案2】:

此错误消息...

System.InvalidOperationException: '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 (SessionNotCreated)'

...暗示GeckoDriver 无法启动/生成新的浏览上下文,即Firefox 浏览器 会话。

可能 浏览器安装在非常规位置,因此GeckoDriver 无法访问firefox 二进制文件。


解决方案

作为解决方案,通过FirefoxOptionsBrowserExecutableLocation 参数传递firefox.exe 二进制文件的绝对位置,如下所示:

FirefoxOptions options = new FirefoxOptions();
options.BrowserExecutableLocation = ("C:\\Program Files\\Mozilla Firefox\\firefox.exe"); //location where Firefox is installed
WebDriver driver = new FirefoxDriver(options);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-18
    • 2018-03-31
    • 2022-06-29
    • 2021-09-22
    • 2021-03-02
    • 2021-05-06
    • 1970-01-01
    • 2021-03-26
    相关资源
    最近更新 更多