一尘不染

org.openqa.selenium.SessionNotCreatedException:通过Selenium v​​3.11.0启动Firefox v37时,找不到匹配的功能集

selenium

我试图在Firefox中运行网站进行测试,但出现错误“驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置;”
我已经正确设置了路径,但仍然不知道问题出在哪里。这是我的代码:

if (browsers.equalsIgnoreCase("Firefox")) 
{
        String driverPath = System.getProperty("user.dir") + "\\src/test/java\\drivers\\geckodriver.exe";
        System.setProperty("webdriver.firefox.marionette", "false");
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    } else if (browsers.equalsIgnoreCase("Chrome")) {
        // String driverPath = System.getProperty("user.dir") +
        // "\\src\\Drivers\\chromedriver";
        // System.setProperty("webdriver.chrome.driver", driverPath);
        System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    }

这是我的代码的失败跟踪:

FAILED CONFIGURATION: @BeforeClass launchBrowser
org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities
Build info: version: '3.8.0', revision: '924c4067df', time: '2017-11-30T11:36:59.109Z'
System info: host: 'DSCHD-PC-180', ip: '192.168.6.122', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161'
Driver info: driver.version: FirefoxDriver
remote stacktrace: 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
    at Utility.UtilityMethods.openBrowser(UtilityMethods.java:26)
    at TestCases.LoginTestCase.launchBrowser(LoginTestCase.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:455)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:168)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

SKIPPED CONFIGURATION: @AfterClass quitBrowser
SKIPPED: registration

阅读 306

收藏
2020-06-26

共1个答案

一尘不染

为了简化操作,在使用 Selenium Client v3.11.0Firefox v37时, 您需要从 mozilla /
geckodriver
下载最新的
GeckoDriver 并将其保存在系统中的任何位置。接下来,在该行中传递 Key webdriver.gecko.driver* 以及
Value 作为 GeckoDriver绝对路径 ,最后通过 DesiredCapabilities 类将功能
marionatte 设置为 false 并合并到 FirefoxOptions 实例的实例中以启动 Firefox
****
System.setProperty()
__
__*____浏览器如下:

System.setProperty("webdriver.gecko.driver", "C:/path/to/geckodriver.exe");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", false);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
FirefoxDriver driver =  new FirefoxDriver(opt);
driver.get("https://stackoverflow.com");
System.out.println("Application opened");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();

更新资料

根据您的评论更新,您正在使用 GeckoDriver v0.20.1

但是,如果您回顾一下 GeckoDriver v0.18.0 的发行说明,它显然会提到:

geckodriver now recommends Firefox 53 and greater

因此,使用 GeckoDriver v0.18.0 及更高版本,您必须强制使用Firefox
53及更高版本。要摆脱这种限制,您可以降级到以下任一版本:

  • GeckoDriver v0.17.0
  • GeckoDriver v0.16.1
2020-06-26