SessionNotCreatedException:无法创建新服务:GeckoDriverService

时间:2017-08-23 09:22:15

标签: java linux selenium

我正在使用:

  • Java 1.8
  • Selenium 3.5.0
  • Selenium Standalone Server 3.5.0
  • 硒中心OS - RHEL 7
  • Geckodriver 18
  • Firefox 55

我有一个错误:

    org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService
    Build info: version: '3.5.0', revision: '8def36e068', time: '2017-08-10T23:00:22.093Z'
    System info: host: 'NC9128105064', ip: '9.128.105.64', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-327.el7.x86_64', java.version: '1.8.0_91'
    Driver info: driver.version: unknown
    Command duration or timeout: 16 milliseconds
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
        at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
        at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
        at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$24(ProtocolHandshake.java:360)
        at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
        at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
        at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
        at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
        at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
        at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
        at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
        at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:363)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:137)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:254)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:174)
        at Utils.BrowserDriver.ff(BrowserDriver.java:66)
        at TestCases.Category.LogInCreateCategory.logIn(LogInCreateCategory.java:29)
        at TestCases.TestRunner.main(TestRunner.java:82)

选择firefox的代码:

            public static WebDriver ff() {

            File firefoxfile = new File(PropertyReader.getProperty("firefox"));
            System.setProperty("webdriver.gecko.driver", firefoxfile.getPath());

            WebDriver wd = null;//new RemoteWebDriver(dc);

            try {
                URL url = new URL("http://" + TestRunner.SELENIUM_HUB + ":4444/wd/hub");
                FirefoxProfile fp = new FirefoxProfile();
                // set something on the profile...
                DesiredCapabilities dc = DesiredCapabilities.firefox();
                dc.setCapability("marionette", true);
                //dc.setCapability(FirefoxDriver.PROFILE, fp);

                wd = new RemoteWebDriver(url, dc);
            } catch (MalformedURLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            return wd;
    }

我认为Linux上geckodriver的路径出了问题。我尝试了几个选项:

  • /drivers/geckodriver
  • drivers/geckodriver
  • root/drivers/geckodriver
    但没有成功

Linux上带geckodriver的目录中的pwd给了我:
/root/drivers

2 个答案:

答案 0 :(得分:0)

请将geckodriver更新到最新版本。

File firefoxfile = new File(PropertyReader.getProperty("C://users//geckodriver.exe"));
 System.setProperty("webdriver.gecko.driver", firefoxfile.getPath());

答案 1 :(得分:0)

我遇到了同样的问题,并通过将系统属性设置为 geckodriver.exe 路径来解决此问题,如下所示:

System.setProperty("webdriver.gecko.driver","C:\\tech2\\selenium\\geckodriver.exe");

在实例化驱动程序之前设置属性。

我找到了解决方案here。这个问题似乎特定于selenium 3.x +。