Search code examples
javaseleniumgeckodriverselenium3

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


Selenium standalone server lib is added, Gecko driver (latest version). All set but error still appears.

I'm using:

  • Java 8 Update 191
  • Windows 10, 64 bit
  • Mozilla 48.0.2
  • Selenium 3.141.59

Code:

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/");
    }
}

Error when ran in 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.access$100(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)


Solution

  • Exception in thread "main" java.lang.IllegalStateException: This exception comes when your gecko driver version doesn't support the firefox browser version you are using.

    To check which gecko driver version is compatible with your browser follow the link below.

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

    There you'll find all the details on each driver, its properties and compatible firefox version.