Reputation: 31
Please help me with this issue that is recurring every time I run my code. I have extracted Geckodriver files in C Drive but when I run my code, the error that comes up is 'Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\geckodriver.exe'.
My code is given below:
package Basics;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Browserinvocation {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();//FirefoxDriver class is used to implement methods present in Webdriver-Invocation of browser
driver.get("https://www.amazon.in/");// Get method to hit the url in browser
}
}
Error in console :
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\geckodriver.exe at com.google.common.base.Preconditions.checkState(Preconditions.java:534) at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:131) at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41) at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:141) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339) at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:158) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98) at Basics.Browserinvocation.main(Browserinvocation.java:13)
Upvotes: 1
Views: 10043
Reputation: 13
Above exception occurs whenever Precondition does not find path of relevant driver mentioned in System.setProperty() method by any reason like below:
Just check once before execution.
Upvotes: 1
Reputation: 1
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
Here remove . in between gecko and driver
Upvotes: 0
Reputation: 4739
Your code is running at my side, might be you are not extracting the gecko driver.
Change the path and try it once, it should worked
Please let me know selenium jars version and your firefox browser version
System.setProperty("webdriver.gecko.driver", "C:/Users/sankalp.gupta/Desktop/JAVASEL/geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://www.amazon.in");
System.out.println(driver.getCurrentUrl());
driver.close();
Upvotes: 0
Reputation: 3350
You should add the path to geckodriver.exe
using /
rather than \\
. Change your line
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
to the following
System.setProperty("webdriver.gecko.driver","C:/geckodriver.exe");
Upvotes: 0