top of page
  • Writer's picturekhyati sehgal

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chro

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:177)

at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:106)
 

Problem statement:

Look at the below code and analyze the issue with the snippet.

import org.junit.Before;
 import org.junit.Test;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.chrome.ChromeDriver;
 WebDriver driver = new ChromeDriver();
 
@Before
 public void startDriver() {
 System.setProperty("webdriver.chrome.driver",
 "~Path to your chrome drivero~//chromedriver_win32//chromedriver.exe");
driver.get("http://www.google.in");
 }

@Test
 public void getWebSite() {
 }
@After
 public void killSession() {
 driver.close();
 }}
 

What this code is doing is it is instantiating the driver first before any function is called WebDriver driver = new ChromeDriver(); as an instance variable, what it will do is it will make an instance of selenium web driver and keep it in the driver.

Now when you define the path of the web driver in @Before method then it already has a definition of the driver and that does not have any path of chrome driver in it. So during the execution of this code, the above error will come and no driver shall get open.

Resolution

 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.chrome.ChromeDriver;
 public class UserInterfaceTest {
 WebDriver driver = null;// you need to instantiate driver first and give it some values like null .
 @Before
 public void startDriver() {
 System.setProperty("webdriver.chrome.driver",
 "F://Selenium//chromedriver_win32//chromedriver.exe"); // Here mention the path to run chromedriver as property
 driver = new ChromeDriver(); //  Here you need to tell which driver you want to use
 driver.get("http://www.google.in");
 }
 @Test
 public void getWebSite() {
 System.out.println("Test 1");
 }
 @After
 public void killSession() {
 driver.close();
 }
 

Conclusion

This code is a fix for the above error, What this will do is it will take null value first will instantiation of Web driver. And further when you want to use it in any method then only it will take the value of driver i.e. either it is Firefox or Chrome or any other browser you want to run your tests on.

And then it will take the path of the driver once you will define which driver you want to use. So for cases where you want to use a web browser other than Firefox you need to define driver for the same and also need to set the property for the same web browser.

And this is how you can get rid of this issue.

0 views0 comments

Recent Posts

See All
bottom of page