1

Placing geckodriver in resources and mapping it works on the machine am working on, but not on any other machine. i need it to export it to other machines, so that i am creating a jar which i need to run on any other machine, but when running the jar on other machine is throwing out "The path to the driver executable must be set by the webdriver.gecko.driver system property" error.

public static WebDriver createDriver() 
{
        WebDriver driver= new FirefoxDriver();
        System.setProperty("webdriver.gecko.driver", "./src/main/resources/geckodriver");
        driver = new FirefoxDriver(FirefoxDriverProfile());
        driver.manage().window().maximize();
        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);
        return driver;

 [Please take a look at the image]
https://i.stack.imgur.com/khGBu.png
  • Possible duplicate of [Selenium using Java - The path to the driver executable must be set by the webdriver.gecko.driver system property](http://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr) – Andersson Mar 08 '17 at 08:22

2 Answers2

2

It seems that you're missing the file extension. The following works for me using relative file paths:

System.setProperty("webdriver.gecko.driver", ".\\WebDrivers\\geckodriver.exe");

Edit: Have you tried to swap the order of these two lines? Unless I'm mistaken, the system property should be set prior to the creation of the WebDriver.

WebDriver driver= new FirefoxDriver();
System.setProperty("webdriver.gecko.driver", "./src/main/resources/geckodriver");

Should be

System.setProperty("webdriver.gecko.driver", "./src/main/resources/geckodriver");
WebDriver driver= new FirefoxDriver();
Inphinitii
  • 21
  • 3
0

You can set it like:-

System.setProperty("webdriver.gecko.driver", new File("./src/main/resources/geckodriver").getCanonicalPath());
Paras
  • 3,197
  • 2
  • 20
  • 30