在Linux上运行Selenium时出现异常 - “驱动程序版本未知”错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Linux上运行Selenium时出现异常 - “驱动程序版本未知”错误相关的知识,希望对你有一定的参考价值。
我是Selenium的新手,并编写了一个代码,用于在firefox的无头模式下运行测试用例。它正在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");
另一答案
这是因为selenium服务器找不到chromedriver 如果您的chromedriver放入/ usr / local / bin / 执行:
sudo chown root:root /usr/local/bin/chromedriver
sudo chmod 0755 /usr/local/bin/chromedriver
以上是关于在Linux上运行Selenium时出现异常 - “驱动程序版本未知”错误的主要内容,如果未能解决你的问题,请参考以下文章
使用 selenium 运行 django-test 时出现断管错误
在 django 开发服务器上打开页面时出现错误的状态行异常