0

我无法在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
4

2 回答 2

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");
于 2018-04-30T17:02:38.833 回答
0

此错误消息...

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

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

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

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

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

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");
于 2018-04-30T18:41:24.657 回答