Reputation: 51
I am getting below error while trying to execute my selenium code shown below:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Demo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("www.google.com");
}
}
Error - Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Selenium\Introduction\C:\chromedriver at com.google.common.base.Preconditions.checkState(Preconditions.java:585) at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:146) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:141) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at Demo.main(Demo.java:11)
I have placed the chrome driver in the location mentioned and the version is also double checked.
Upvotes: 0
Views: 236
Reputation: 4035
This is very minor change with static mode, try with :
static WebDriver driver;
static String driverpath = "C:\\chromedriver.exe";
public static void main(String [] args)
{
System.setProperty("webdriver.chrome.driver", driverpath);
driver = new ChromeDriver();
}
As we are executing Java static main method, its requires to handle driver with Static variables.
Upvotes: 0