"unknown error","message":"connection refused","stacktrace" 在 Mac OS X 上尝试通过 GeckoDriver 和 Selenium 使用 firefoxprofile

"unknown error","message":"connection refused","stacktrace" while trying to use firefoxprofile through GeckoDriver with Selenium on Mac OS X

我在创建 firefox 驱动程序时遇到连接被拒绝的错误。

System.setProperty("webdriver.gecko.driver", "path to gecko driver");
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(FirefoxDriverLogLevel.FATAL);
options.setAcceptInsecureCerts(true);
options.addArguments("-profile", "./firefoxprofile");
options.setHeadless(true);
LOGGER.info("Completed setting firefox optons");
WebDriver driver = new FirefoxDriver(options);

日志:

 1550014357421  mozrunner::runner   INFO    Running command: "/Applications/Firefox.app/Contents/MacOS/firefox-bin" "-marionette" "-profile" "./firefoxprofile" "-foreground" "-no-remote"
 1550014357464  geckodriver::marionette DEBUG   Waiting 60s to connect to browser on 127.0.0.1:61008
 [GFX1-]: [OPENGL] Failed to init compositor with reason: FEATURE_FAILURE_OPENGL_CREATE_CONTEXT
 Can't find symbol 'GetGraphicsResetStatus'.
 1550014417545  mozrunner::runner   DEBUG   Killing process 38393
 Exiting due to channel error.
 1550014417592  webdriver::server   DEBUG   <- 500 Internal Server Error {"value":{"error":"unknown error","message":"connection refused","stacktrace":""}}

Web 服务器是 运行,我可以使用 curl 命令对其进行测试,我尝试在 gecko 驱动程序 bin 文件上使用 777 权限。

还将 Gecko 驱动程序更新到最新版本 (0.24.0)

你的配置看起来不错。

我在 Linux 中遇到了类似的问题。

  • 在我的例子中,解决方案是用所有版本的 gecko 驱动程序进行测试,其中一个版本有效。

  • 您还可以检查您的IDE(eclipse、intellij)的o.s用户是否与firefox的用户相同。在我的例子中,eclipse 以 root 用户启动,但 firefox 无法以 root 用户启动。

希望对你有所帮助。

使用 Selenium v3.xGeckoDriver v0.24.0Firefox Quantum v65.0 测试执行[=20] 的每个 运行 上使用 new Firefox 配置文件 =] 您可以使用以下代码块:

System.setProperty("webdriver.gecko.driver", "C:\path\to\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(new FirefoxProfile());
options.setLogLevel(FirefoxDriverLogLevel.FATAL);
options.setAcceptInsecureCerts(true);
options.setHeadless(true);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");

You can find a detailed discussion in

我在 Windows 使用 python 时遇到了同样的问题。请确保您的 Firefox 浏览器版本也是最新版本。

找了很多,终于发现是因为浏览器之前的一个实例是运行。请记住,不是像我打开的另一个实例,而是之前由 selenium 打开的实例。如果可以,请关闭所有后台浏览器进程。我重新启动了我的系统,只要我记得做 browser.quit().

,它就可以正常工作

如果您在正确关闭对象之前停止程序,后台实例有可能会保留 运行,除非 eclipse 或您使用的任何 IDE 关闭它。