I tried to provide my Selenium Webdriver test with all needed drivers in a separate folder under the src.

The structure looks like
enter image description here

I tried to create a new instance of the webdriver like this:

System.setProperty("webdriver.ie.driver", "pathToTheFFDriver");
WebDriver driver = new FirefoxDriver();

The problem is now to create a proper path to the driver. When I copied the driver to somewhere outside of the project, e.g. "C:\drivers\geckodriver.exe" I can create a working path. But how can I access the file without copying it first?

I tried the following:

System.setProperty("Webdriver.gecko.driver", "driver/geckodriver.exe");

System.setProperty("Webdriver.gecko.driver", "./driver/geckodriver.exe");

System.setProperty("Webdriver.gecko.driver", "./src/driver/geckodriver.exe");

But I always get the same error

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

What am I missing? How can I access the driver directly without copying it first?

1 Answer 1


The answer over at SO:

System.setProperty("webdriver.gecko.driver", "path_to_driver");
WebDriver driver = new FirefoxDriver();

I prefer to put the drivers in a folder (like, C:\Selenium) and add that folder to my system PATH and not define it in code. This makes it easier to run on different systems as each system has its own PATH defined (as pointed out in the comments of the answer I linked).

  • Thanks for your answer, but my problem is not the path to the driver when the file is copied in a previous step somewhere on the system. My goal is to avoid copying the file because it is already there. Jun 8, 2017 at 5:41
  • So you want to use the driver from the directory ./src/driver in your source code?
    – kirbycope
    Jun 8, 2017 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.