Java Selenium Chromedriver.exe Does not Exist IllegalStateException


An IllegalStateException is thrown while working with Chrome browser if the chromedriver.exe file path is set incorrectly in the method System.setProperty. Once this executable file is downloaded, it has to be extracted. Then its path should be copied and added as a parameter to the System.setProperty method.

Syntax

System.setProperty("webdriver.chrome.driver",
"C:\Users\ghs6kor\Desktop\DebomitaJava\chromedriver.exe")

Also, it must be remembered that, for Windows, we have to specify the .exe extension while including the path. But it is not required for Mac or Ubuntu. We should also ensure that the chromedriver.exe file that we are using is compatible with the local Chrome browser version.

Let us see an example for IllegalStateException.

Example

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class PathChromeDriver{
   public static void main(String[] args) {
      //path of chromedriver.exe set
      System.setProperty("webdriver.chrome.driver",
         "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      //implicit wait
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //launch URL
      driver.get("https://www.tutorialspoint.com/about/about_careers.htm");
      System.out.println("Page title is: " + driver.getTitle());
      driver.quit();
   }
}

Output

Updated on: 06-Apr-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements