java.lang.IllegalStateException: The driver executable does not exist

If you are developing Selenium programs in Java, then you might seen this java.lang.IllegalStateException so many times. It is not so rare, as it looks like. Let’s try to fix this exception with a simple example.

When you are working with Selenium, Web browsers and its Drivers / Binary files, you might face exceptions such as – Exception in thread “main” java.lang.IllegalStateException: The driver executable does not exist: (and some executable file location).

In this Selenium and Java guide, we will see how to fix The driver executable does not exist exception. These errors occur due to the use of invalid names of the directory or sometimes the driver itself. Let’s understand and fix the Selenium Framework Error- The driver executable does not exist.

Here’s how to correctly place a custom driver/binary file in a Selenium Framework with Java based project –

To Set Chrome Driver in Project, Right Click on Project Name > Create New Folder > Paste the ChromeDriver Binary

 

Situation :

Assume, we need to test the functionality of Google’s home page. For that, we need to write a Selenium Framework and Java-based script, such as –

package com.shubhamklogic.selenium.browsertesting;
 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
 
public class BrowserTesting {
 
    public static void main(String[] args) {
 
        testOnChrome();
 
    }
 
    public static void testOnChrome() {
 
        String projectsPath = System.getProperty("user.dir");
        System.setProperty("webdriver.chrome.driver", projectsPath + "/TheDriver/chromedriver.exe");
 
 
        WebDriver theDriver = new ChromeDriver();
        theDriver.get("https://google.com/");
 
 
        theDriver.close();
    }
 
}

 

To test the above Selenium script, when we run the code, we will get the below exception –

Error :

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: D:\EclipseProjects\SeleniumFrameworkJavaProject\TheDriver\chromedriver.exe
	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$00(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.<init>(ChromeDriver.java:123)
	at com.shubhamklogic.selenium.browsertesting.BrowserTesting.testOnChrome(BrowserTesting.java:20)
	at com.shubhamklogic.selenium.browsertesting.BrowserTesting.main(BrowserTesting.java:10)

 

Reason –

One of the reasons for getting the above Exception is that, the wrong path to the chrome driver. As you can see in the above screengrabs, we created a separate folder/directory named TheDrivers to keep all our custom drivers, but we provide the invalid path to the System environment, we will get this exception.

 

Solution : java.lang.IllegalStateException: The driver executable does not exist

To resolve this exception, Re-analyse the path to the driver and put the correct name and slashes according to your Operating system.

  • If you are working on a Windows / Linux machine, then you can place the forward-slash / up to the driver name.
  • If you’re working on a Mac machine, then just mention the path up to the directory containing the driver. There is no need to go to the driver name for these systems.

In order to fix the Exception in thread “main” java.lang.IllegalStateException: The driver executable does not exist: D:\EclipseProjects\SeleniumFrameworkJavaProject\TheDriver\chromedriver.exe, in this case, we need to replace TheDriver with the correct directory name TheDrivers.

Leave a Comment