Exception in thread "main" java.lang.IllegalStateException: The driver executable must exist error using Selenium and Java

Issue

I am unable to execute my first selenium code. Tried changing webdriver path several times but that didn’t work.

Code trials:

package Learningday1;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class FirstScript {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "‪‪‪C:\\Users\\amann\\Downloads\\chromedriver_win32\\chromedriver.exe");
        WebDriver driver = new ChromeDriver(); 
        driver.get("https://selenium.dev");
        System.out.println(driver.getTitle());
        driver.quit();
    }

}

Error:

Exception in thread "main" java.lang.IllegalStateException: The driver executable must exist: C:\Users\amann\eclipse-workspace\Selenium learning 2.0\???C:\Users\amann\Downloads\chromedriver_win32\chromedriver.exe
    at org.openqa.selenium.internal.Require$FileStateChecker.isFile(Require.java:342)
    at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:147)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:142)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:39)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:233)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:437)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:128)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:49)
    at Learningday1.FirstScript.main(FirstScript.java:10)

Snapshot:

enter image description here

Solution

There is some ambiguity between your code trials and the error stacktrace.

In your code you mentioed the ChromeDriver as:

‪‪‪C:\\Users\\amann\\Downloads\\chromedriver_win32\\chromedriver.exe

Where as the error stacktrace mentions the driver executable doesn’t exists at:

C:\Users\amann\eclipse-workspace\Selenium learning 2.0???C:\Users\amann\Downloads\chromedriver_win32\chromedriver.exe

Solution

Ensure that you have unzipped the ChromeDriver and placed with the sub-directory:

C:\\Users\\amann\\Downloads\\chromedriver_win32

and you need to mention the absolute path within the System.setProperty() line as:

System.setProperty("webdriver.chrome.driver", "‪‪‪C:\\Users\\amann\\Downloads\\chromedriver_win32\\chromedriver.exe");

Update

You have 2 projects with almost similar names, a maven project and another a Java project. The name starting with Selenium learning.

Try to avoid same name for multiple projects and blank spaces within the project names. Example SeleniumTest, SeleniumProgram, etc.

PS: You may opt to delete the current project and create a new one.


References

You can find a relevant detailed discussion in:

Answered By – undetected Selenium

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published