无法在当前系统上找到 Firefox (Firefox 47)

Could not locate Firefox on the current system (Firefox 47)

Firefox自升级到47版本后,Selenium停止工作。 我遵循了 Mozilla 关于 Marionette 驱动程序建议的 Javascript (Node.js) 步骤,但控制台显示它在我当前的系统上找不到 Firefox,但是浏览器的路径很好,很标准。 错误是 "Could not locate Firefox on the current system" 在 C:\Users\\node_modules\selenium-webdriver\firefox\binary.js:115:11

如果重要的话,我使用 WebdriverJS。

我遇到过这种情况,它似乎总是很随机。这是一个远景,但请尝试更改路径,然后将原来的路径放回去,这在过去对我有用。

我遇到了类似的问题,并且看到 GG group. Your only solution for now might be to downgrade - https://ftp.mozilla.org/pub/firefox/releases/46.0.1/

中讨论的 Firefox 47 和 WebDriver(JS 和其他语言)似乎存在大量问题

诚然,降级并没有解决我的问题,但是ymmv

我遇到了同样的问题,通过从 https://www.mozilla.org/en-US/firefox/developer/ 下载开发版解决了这个问题。显然在使用 firefox 的开发者版本方面存在一些冲突。
在 node_modules/selenium-webdriver/firefox/binary.js,第 99 行,这段代码:

let exe = opt_dev
        ? '/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin'
        : '/Applications/Firefox.app/Contents/MacOS/firefox-bin';
    found = io.exists(exe).then(exists => exists ? exe : null);

选择了DeveloperEdition,但我没有,导致found为null,后来在115行报错。

会不会是你的Firefox没有安装在默认位置?我的安装在 C:\Users\(username)\AppData\Local\Mozilla Firefox\,我得到了和你一样的错误信息。

浏览代码(感谢@achie),我在node_modules\selenium-webdriver\firefox\index.js中发现了以下内容:

* On Windows and OSX, the FirefoxDriver will search for Firefox in its
* default installation location:
*
* * Windows: C:\Program Files and C:\Program Files (x86).
* * Mac OS X: /Applications/Firefox.app
*
* For Linux, Firefox will be located on the PATH: `$(where firefox)`.

换句话说,将Firefox目录放在Windows上的PATH变量中甚至没有任何用处。

但源码继续:

* You can configure WebDriver to start use a custom Firefox installation with
* the {@link Binary} class:
*
*     var firefox = require('selenium-webdriver/firefox');
*     var binary = new firefox.Binary('/my/firefox/install/dir/firefox-bin');
*     var options = new firefox.Options().setBinary(binary);
*     var driver = new firefox.Driver(options);

在我的例子中,它变成了:

var firefox = require('selenium-webdriver/firefox');
var binary = new firefox.Binary('C:\Users\(username)\AppData\Local\Mozilla Firefox\firefox.exe');
var options = new firefox.Options().setBinary(binary);
var driver = new firefox.Driver(options);

现在 Selenium 找到了我的 Firefox,但我收到下一条错误消息:

Error: Timed out waiting for the WebDriver server at http://127.0.0.1:53785/hub

我也试过var driver = new webdriver.Builder().forBrowser('firefox').setFirefoxOptions(options).build();,但没有任何区别。

希望这对您有所帮助!

Mozilla 的工作人员建议使用 Marionette 驱动程序,因为 Selenium Webdriver 2.53 和 Firefox 47/48 存在启动崩溃问题

https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver

最新的 Firefox 48 和 Selenium Webdriver 3.0.0 解决了这个特殊问题。