gpt4 book ai didi

java - 在 Linux 上运行 Selenium 时出现异常 - 'Driver version unknown' 错误

转载 作者:IT王子 更新时间:2023-10-29 00:42:52 27 4
gpt4 key购买 nike

我是 Selenium 的新手,编写了一段代码以在 firefox 的 headless 模式下运行测试用例。它在 Windows 7 上运行,但当我尝试使用 RemoteWebDriver 在 Centos 7.3 操作系统上执行相同操作时遇到此异常。

org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities {acceptInsecureCerts: true, browserName: firefox, firefox_binary: /us
/bin/firefox, marionette: false, moz:firefoxOptions: {args: [--disable-web-security, --headless], binary: /usr/bin/firefox, prefs: {}}}
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'localhost.localdomain', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-514.26.1.el7.x86_64', java.version: '1.8.0_73'
Driver info: driver.version: unknown
at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:117) ~[na:na]
at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:84) ~[na:na]
at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:68) ~[na:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) ~[tomcat-embed-core-8.0.32.jar!/:8.0.32]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[tomcat-embed-core-8.0.32.jar!/:8.0.32]
at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:841) ~[na:na]
at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:535) ~[na:na]
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) ~[na:na]
at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595) ~[na:na]
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) ~[na:na]
at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1253) ~[na:na]
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168) ~[na:na]
at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473) ~[na:na]
at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564) ~[na:na]
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166) ~[na:na]
at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1155) ~[na:na]
at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[na:na]
at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) ~[na:na]
at org.seleniumhq.jetty9.server.Server.handle(Server.java:561) ~[na:na]
at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:334) ~[na:na]
at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:251) ~[na:na]
at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279) ~[na:na]
at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:104) ~[na:na]
at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124) ~[na:na]
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247) ~[na:na]
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140) ~[na:na]
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) ~[na:na]
at org.seleniumhq.jetty9.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:243) ~[na:na]
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679) ~[na:na]
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:597) ~[na:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_73]

我什至在 DesiredCapabilities 中指定了驱动程序版本,但没有成功。我什至尝试过使用 ChromeDriver,但仍然遇到同样的异常。以下是我尝试过的一些版本。

Selenium Standalone - 2.53.0, 3.4.0, 3.8.1 etc
Gecko Driver - 0.16.0, 0.18.0, 0.19.1 etc
Chrome Driver - 2.18, 2.30, 2.35 etc
Mozilla - 45.7, 55.0.3, 57.0 etc
Chrome - 45.0.2454.101-1, 64.0.3282.119-1 etc

我在同一台服务器上运行 selenium 独立集线器和节点。这是相同的代码片段。

System.setProperty("webdriver.gecko.driver", "/root/selenium/driver/geckodriver");

FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--disable-web-security", "--headless");

String Xport = System.getProperty("lmportal.xvfb.id", ":1");
firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);

FirefoxOptions firefoxOptions = new FirefoxOptions().setLegacy(true);
firefoxOptions.setBinary(firefoxBinary);

WebDriver driver = new RemoteWebDriver(new URL("http://" + "localhost" + ":" + "4444" + "/wd/hub"), firefoxOptions.toCapabilities());
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://google.com/");

// Take snapshot of browser
File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(srcFile, new File("ffsnapshot.png"));
} catch (IOException e) {
e.printStackTrace();
}
driver.quit();

我什至运行一个 Xvfb 服务器来虚拟运行 firefox。如果我的方法/代码有误以及如何解决此问题,请纠正我。

最佳答案

通过添加此属性使其适用于 firefox。

System.setProperty("webdriver.firefox.marionette", "false");

关于java - 在 Linux 上运行 Selenium 时出现异常 - 'Driver version unknown' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48506037/

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