GeckoDriver exception while launching Firefox

GeckoDriver exception while launching Firefox

Hello friends, with Selenium Webdriver versions after release Selenium 3.0 you might have faced the issue of Illegal State Exception while launching Firefox browser. In this tutorial, we will present the resolution for this exception and also its root cause.

Exception Detail

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

Steps to reproduce

Launch the Firefox browser with Selenium 3.0 and above versions directly without setting “webdriver.gecko.driver” path.

WebDriver driver = new FirefoxDriver();

Resolution

  1. Download geckodriver.exe from GeckoDriver Github Release Page. Make sure to download the right driver file based on your platform and OS version.
  2. Set the System Property for “webdriver.gecko.driver” with the geckodriver.exe path.
  3. System.setProperty(“webdriver.gecko.driver”,”geckodriver.exe path”); (This is similar to the way we use to set system property for chromedriver.exe).

Code Snippet

System.setProperty("webdriver.gecko.driver", pathToGeckoDriver + "\geckodriver.exe");
WebDriver driver = new FirefoxDriver();

От QA genius

Adblock
detector