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 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();
- Download geckodriver.exe from GeckoDriver Github Release Page. Make sure to download the right driver file based on your platform and OS version.
- Set the System Property for “webdriver.gecko.driver” with the geckodriver.exe path.
- System.setProperty(“webdriver.gecko.driver”,”geckodriver.exe path”); (This is similar to the way we use to set system property for chromedriver.exe).
System.setProperty("webdriver.gecko.driver", pathToGeckoDriver + "\\geckodriver.exe"); WebDriver driver = new FirefoxDriver();
Kuldeep is the founder and lead author of ArtOfTesting. He is skilled in test automation, performance testing, big data, and CI-CD. He brings his decade of experience to his current role where he is dedicated to educating the QA professionals. You can connect with him on LinkedIn.