5
votes

I have this exception since I upgraded to 3.0 beta with Firefox.

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property

6

6 Answers

8
votes

It seems now we need to manually download and set path to the driver executable for Mozilla Firefox also just like chromedriver.

Following is what you need to do:-

  1. Go to http://docs.seleniumhq.org/download/
  2. Scroll down to "Third Party Drivers, Bindings, and Plugins" section on downloads page
  3. Click on Mozilla GeckoDriver and download(zip) latest version v0.10.0 for your operating system.
  4. Extract on your desired location i.e. c:\GeckoDriver\geckodriver.exe

Now you need to set system property and write following lines to initialize FireFoxDriver object:-

System.setProperty("webdriver.gecko.driver", "C:\GeckoDriver\geckodriver.exe");

WebDriver driver = new FirefoxDriver();

driver.get("http://seleniumhq.com");

Thats it!

2
votes

Try below code in JAVA, and its working fine me

  1. need to updated selenium and selenium drivers for java

  2. updated firefox, firefox driver

in below code "C:\\Drivers\\geckodriver.exe" is path of your webdriver

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FirstTestCase {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        //WebDriver driver =new FirefoxDriver();

        System.setProperty("webdriver.gecko.driver", "C:\\Drivers\\geckodriver.exe");
        FirefoxDriver driver = new FirefoxDriver();
        driver.get("https://www.syncfusion.com/");
         System.out.println("Successfully opened the website www.Syncfusion.com"); 
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         driver.quit();
    }

}
1
votes
System.setProperty("webdriver.gecko.driver","C://Program Files (x86)//geckodriver-v0.11.1-win64//geckodriver.exe");
String testurl = "http://www.seleniumhq.com";
WebDriver driver = new FirefoxDriver();
driver.get(testurl);

Normally this happens when the FF version is above 45 and thats when we download gecko driver (https://github.com/mozilla/geckodriver/releases). After this unzip the contents of the folder and drag and drop the exe file of gecko driver to this folder (src/main/resources) if you have created a maven project.

1
votes

We use System.setProperty to provide the path of chromedriver/iedriver etc. Below is the declaration of java.lang.System.setProperty() method:

public static String setProperty(String key, String value)

key : Name of the system property

value: Value of the system property

e.g. System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.exe");

webdriver.chrome.driver : Chrome Driver (Name of system property) src/test/resources/chromedriver.exe : Path of chromedriver (value of system property)

Usually, we encounter IllegalArgumentException when key is empty.

0
votes

public class WaitTestCase { WebDriver driver;

@Test ()    
public void TC_Wait(){

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

driver = new FirefoxDriver();


        driver.get("http:\\yahoo.com");

        driver.quit();
}

}

0
votes
package webdriver_Commands;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FirefoxFacebook {

    public static void main(String[] args) throws InterruptedException {

      System.setProperty("webdriver.gecko.driver","C:\\Driver\\geckodriver.exe");

      WebDriver driver=new FirefoxDriver();
      driver.get("https:\\www.google.com");
    }
}