3

I am trying to run my first webdriver script in eclipse. using jre1.8.0_1111. I used the following code but it shows error.please help me with the code.

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

 public class Trial { 
    static void main(String[] args) { 
    WebDriver driver = new FirefoxDriver(); 
    String baseUrl = "google.com";    
    System.setProperty("webdriver.gecko.driver", "C:\\Users\\Naik\\Downloads\\geckodriver-v0.11.1-win64\\geck‌​odriver.exe"); 
    driver.get(baseUrl); 
   }

Error stack

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 github.com/mozilla/geckodriver. The latest version can be downloaded from github.com/mozilla/geckodriver/releases

prithvi394
  • 221
  • 1
  • 6
ayav
  • 73
  • 1
  • 12
  • Possible duplicate of http://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr/41463095#41463095 – A user Jan 04 '17 at 12:02

3 Answers3

4

Download the geckodriver from the below URL and save it on your local machine.

https://github.com/mozilla/geckodriver/releases

Then set the right path where the geckodriver.exe is saved.Moreover the set property must be used before declaring the driver!

 public class Trial { 
  public static void main(String[] args) {
    String baseUrl = "google.com";
    System.setProperty("webdriver.gecko.driver", "C:\\Users\\Naik\\Downloads\\geckodriver-v0.11.1-win64\\geck‌​odriver.exe"); 
    WebDriver driver = new FirefoxDriver(); 
    driver.get(baseUrl); 
  }
prithvi394
  • 221
  • 1
  • 6
  • yes i had already downloaded geckodriver and included that path in my code... and got the above error – ayav Dec 28 '16 at 14:25
  • Did you try the code i mentioned above? System property has to be set before driver declaration which isn't the case in your code.Try again after rectifying it! – prithvi394 Dec 28 '16 at 14:45
3

You need to first download GeckoDriver. After that, you can either add it to the PATH variable in environment variables sections, or you can set the path using "webdriver.gecko.driver" property. Check the below article for the steps -

http://www.automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/

Also, please make sure that you are using the latest versions of Selenium, GeckoDriver and Firefox.

Anish Pillai
  • 1,023
  • 7
  • 8
  • yes i had already downloaded geckodriver and included that path in my code... and got the above error @Anish – ayav Dec 28 '16 at 14:25
1

If you don't want to download geodriver, the other way is

Downgrade the Firefox browser version to 44 or more lesser and run your test.

https://ftp.mozilla.org/pub/firefox/releases/

Then you don't have to use gecko driver.

To downgrade firefox to lower version, first uninstall Firefox and the download and install from the link above mentioned

A user
  • 1,060
  • 3
  • 19
  • 47