org.openqa.selenium.SessionNotCreatedException:尝试使用Selenium v​​3.8.1启动Firefox时无法找到匹配的功能集

时间:2018-04-30 16:06:45

标签: java selenium selenium-webdriver geckodriver mutablecapabilities

我无法在 Selenium 3.8.1

中使用 geckodriver 启动Firefox浏览器

这是我的代码

public class LoginTest {
    @SuppressWarnings("deprecation")
    @Test
    public static void logintest() {
        System.setProperty("webdriver.gecko.driver",
            "C:\\Users\\abc\\Downloads\\geckodriver.exe");
        DesiredCapabilities dc = DesiredCapabilities.firefox();
        dc.setCapability("marionnete", true);
        constants.driver = new FirefoxDriver(dc);
        constants.driver.get("https://www.amazon.in");
        constants.driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        constants.driver.manage().window().maximize();
    }

我无法理解为什么它不起作用并且总是给出异常

org.openqa.selenium.SessionNotCreatedException`: Unable to find a matching set of capabilities
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12- 01T18:33:54.468Z'<br>
System info: host: 'ABC-VAIO', ip: '192.168.1.209', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161'<br>
Driver info: driver.version: FirefoxDriver

2 个答案:

答案 0 :(得分:0)

您应该为firefox添加功能请修改您的代码,如下所示:

System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.firefox();
capabilities.setBrowserName("firefox");
capabilities.setVersion("your firefox version");
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setCapability("marionette", false);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("https://www.amazon.in");

答案 1 :(得分:0)

此错误消息......

org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities

...意味着FirefoxDriver在启动新的 WebBrowser 会话时找不到匹配的功能集。

您正在使用 Selenium客户端 v3.8.1 ,但 Selenium客户端的发行说明 v3 .7.0 明确指出:

* Migrated from using `DesiredCapabilities` to either
  `MutableCapabilities` or (preferably) `ImmutableCapabilities`.

因此,您必须使用merge()类中的MutableCapabilities方法在FirefoxOptions的实例中添加功能,并在初始化时传递 FirefoxOptions 对象 Firefox浏览器如下:

System.setProperty("webdriver.gecko.driver", "C:\\Users\\abc\\Downloads\\geckodriver.exe");
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability("marionnete", true);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
constants.driver = new FirefoxDriver(opt);
constants.driver.get("https://www.amazon.in");