I am new to Selenium and have written a code to run a test case in firefox’s headless mode. It is working on Windows 7 but when I tried to do the same on Centos 7.3 OS using RemoteWebDriver running into this exception.
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]
I even specified the driver version in the DesiredCapabilities but no luck. I have even tried with ChromeDriver but still I get the same exception. Here are some of the versions I tried with.
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
I am running the selenium standalone hub and node on the same server. Here is the code snippet for the same.
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();
I am even running an Xvfb server for virtually running firefox. Please correct me if my approach/code is wrong and also on how to get this issue resolved.
Advertisement
Answer
Got this working for firefox by adding this property.
System.setProperty("webdriver.firefox.marionette", "false");