Selenium webdriver – The path to the driver executable must be set by the webdriver.gecko.driver system property

I am using selenium webdriver version 3.3.1 to write selenium test cases and following issue was hit while executing:

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 example.NewTest.beforeTest(NewTest.java:22)

How to fix:

The selenium client bindings will try to load geckodriver from the system PATH, you will need to add the directory containing the executable geckodriver to system PATH property.

  1. If you don’t have the executable geckodriver, download it from https://github.com/mozilla/geckodriver/release
  2. Add the full directory containing geckodriver to system property PATH:
    1. export PATH=$PATH:${path to geckodriver}
  3. OR – set the system property in the java code:       System.setProperty(“webdriver.gecko.driver”, “/Users/ivyhuang/tools/mozilla/geckodriver/v0.15.0/geckodriver”);

    driver = new FirefoxDriver();