20

Need guidance and help in the below one.

When the below code is executed, I am getting error. I am using the latest version of java, eclipse, firefox, and WebDrive jar file.

package firsttest1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class helloselenium {
    public static void main(String[] args) {
        WebDriver driver;
        driver =new FirefoxDriver();
        String url ="http://www.google.com";
        driver.get(url);
    }
}

error....

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 https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases at com.google.common.base.Preconditions.checkState(Preconditions.java:199) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109) at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:38) at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:91) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296) at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:245) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:220) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:215) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:211) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:124) at firsttest1.helloselenium.main(helloselenium.java:12)

Version used: eclipse : neon version java : jdk1.8 fire fox: v48 WebDrive jar file : v 3.0.0 beta2

guide me in resolving this issue.

A_Arnold
  • 3,195
  • 25
  • 39
SJR
  • 199
  • 1
  • 1
  • 6

3 Answers3

42

You are using latest version of Selenium WebDriver i.e. Selenium 3.x, this version of webdriver doesn't support direct firefox launch. You have to set the SystemProperty for webdriver.gecko.driver.

Replace the Code:-

WebDriver driver;
driver =new FirefoxDriver();

With This code:-

WebDriver driver;
System.setProperty("webdriver.gecko.driver", "<Path to your WebDriver>");
driver =new FirefoxDriver();

You can get the information about latest changes here

You can download the latest Gecko driver from here

Paras
  • 3,197
  • 2
  • 20
  • 30
  • 2
    I'm using windows/Eclipse/Selenium --> Adding: System.setProperty("webdriver.gecko.driver", "C:\GeckoDriver\geckodriver.exe"); --> I get an error on this line saying: Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ ) – Selrac Aug 29 '16 at 14:35
  • 2
    Resolved the problem if it helps someone using double backward slash: "C:\\GeckoDriver\\geckodriver.exe" – Selrac Aug 29 '16 at 14:40
  • Any idea on how to solve this using the Seleniumhq jenkins plugin? – Btuman Dec 19 '16 at 19:22
  • Finally it worked!!! I was on version 51 for FF and selenium 3.0. I had to downgrade from 51 to 47 and added the 'client-combined-3.0.1-nodeps.jar' and finally: `WebDriver driver;` `System.setProperty("webdriver.gecko.driver","C:\\kul\\geckod‌​‌​river.exe");` `drive‌​r = new FirefoxDriver();` `driver.get("[google.com](http://google.com)");` – kulNinja Jan 31 '17 at 23:10
8

Download the lastest version for geckoDriver here then set a System property called "webdriver.gecko.driver" and put on it the path to your geckoDriver executable path System.setProperty("webdriver.gecko.driver", "<path to your gecko driver executable>");

BlackDeath
  • 81
  • 2
2

Firefox driver is based on marionette starting with Selenium 3.0. Unlike, 2.x versions, it requires an external executable file. You should add it to your path. For more information, you should have a look at https://github.com/mozilla/geckodriver.

Nicolas Henneaux
  • 11,507
  • 11
  • 57
  • 82