Geckodriver Error: Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by

Geckodriver Error: Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by

添加了 Selenium 独立服务器库,Gecko 驱动程序(最新版本)。一切就绪,但仍然出现错误。

我正在使用:

代码:

package test;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class FistSeleniumTest {

    public static void main(String[] args)

    {

        System.setProperty("webdriver.gecko.driver", "D:\Portnov\Java\First Project\SeleniumTest\libs\geckodriver\geckodriver.exe");

        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);

        WebDriver driver = new FirefoxDriver();
        driver.get("https://seleniumhq.org/");
    }
}

在 Eclipse 中 运行 时出错:

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases at com.google.common.base.Preconditions.checkState(Preconditions.java:847) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134) at org.openqa.selenium.firefox.GeckoDriverService.access0(GeckoDriverService.java:44) at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:167) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355) at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:190) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:147) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:125) at test.FistSeleniumTest.main(FistSeleniumTest.java:10)

线程异常 "main" java.lang.IllegalStateException: 当你的 gecko 驱动程序版本不支持你用来检查的 firefox 浏览器版本时,就会出现这个异常哪个 gecko 驱动程序版本与您的浏览器兼容,请遵循提供的 link。

https://github.com/mozilla/geckodriver/releases

在这里您可以找到关于每个驱动程序及其属性和兼容的 firefox 版本的所有详细信息。