Getting "The path to the driver executable must be set by the webdriver.chrome.driver system property"though set correct path
Asked Answered
C

12

21

My code is very simple code:

WebDriver wd =new ChromeDriver();
  System.setProperty("webdriver.chrome.driver",
                     "D:\\List_of_Jar\\chromedriver.exe");    
       String baseUrl = "https://www.google.com";wd.get(baseUrl);

have downloaded and added jar as "Java-3.4.0" from selenium hq site. Download Google Chrome Driver-2.29 from the same website and located it in "D:\List_of_Jar" path.

When I run the above code I getting an error as

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/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:738)

Getting version error though did proper configuration. so kindly help me for fixing the issue.

Details:

  • OS: Windows XP.
  • Java : JDK1.8 and JRE1.8.
  • Selenium : version 3.4
Concomitance answered 10/6, 2017 at 18:22 Comment(0)
B
29

Driver path should be set before browser launch as given below.

System.setProperty("webdriver.chrome.driver","D:\List_of_Jar\chromedriver.exe");
WebDriver wd =new ChromeDriver();
String baseUrl = "https://www.google.com";
wd.get(baseUrl);"
Bohunk answered 10/6, 2017 at 18:39 Comment(0)
O
13

You are setting chrome driver path incorrectly. Property must be set before WebDriver initialization.

Set property like this -

System.setProperty("webdriver.chrome.driver","D:\\List_of_Jar\\chromedriver.exe")
WebDriver wd =new ChromeDriver();
String baseUrl = "https://www.google.com";
wd.get(baseUrl);" 
Overrule answered 10/6, 2017 at 18:39 Comment(0)
S
9

If you are using IntelliJ IDE, then on IntelliJ without setting up within the 'Run > Edit configurations > VM Options' i will just meet this error:

Failed scenarios:
C:/Users/DATestAdmin/IdeaProjects/TestLogin/src/test/resources/login.feature:4 # Scenario: Successfully logging in

1 Scenarios (1 failed)
3 Steps (3 skipped)
0m0.194s

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property;

So once i've added the path to my chromedriver locally in 'Run > Edit configurations > VM Options':

-Dwebdriver.chrome.driver="C:\\Users\\This\\Is\\Where\\ChromeDriverIs\\chromedriver_win32.exe"

Run > Edit Configurations

I'm now able to launch my Chrome browser successfully.

Subternatural answered 24/4, 2018 at 2:56 Comment(0)
M
5

I totally agree with Murthi, but better is to set relative path to the driver, NOT the absolute.

Relative path looks like:

System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver.exe");

Abosulte: is the path to the driver in your PC.

System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");

Why? It is a good practice to have driver inside your project, not just in your computer. Just find or create folder f.e. resources, inside resources create folder called f.e. drivers and import your driver/drivers exe files there.

Mishamishaan answered 30/12, 2019 at 12:22 Comment(0)
S
1

The below lines works fine

public class TestNGFile {

    public String baseUrl = "https://google.com";
    String driverPath = "C:\\\\Users\\\\Documents\\\\selenium\\\\chromedriver_win32\\\\chromedriver.exe";
    @Test
    public void verifyHomepageTitle() {

        System.out.println("launching chrome browser"); 
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\Documents\\selenium\\chromedriver_win32\\chromedriver.exe");
        //System.setProperty("webdriver.gecko.driver", driverPath);
        WebDriver driver = new ChromeDriver();
        driver.get(baseUrl);
        String expectedTitle = "Google";
        String actualTitle = driver.getTitle();
        Assert.assertEquals(actualTitle, expectedTitle);
        driver.close();
Sylviasylviculture answered 3/3, 2020 at 10:38 Comment(0)
P
0

Try:

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

public class Demo2 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.setProperty("webdriver.chrome.driver", "I:\\Bhasker-ShiroCode\\work\\chromedriver.exe");

        WebDriver driver = new ChromeDriver();

        driver.get("http://google.com");
    }

}

To avoid Error:

  • webdriver.chrome.driver ( should be in small letters )
  • have to give correct chromedriver.exe ( correct path )
  • Import all Selenium jars under class Path
Parallelism answered 15/4, 2019 at 15:18 Comment(0)
U
0

I was getting the same error, since chrome driver was not installed on my machine. Install the chrome driver. Follow: https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver

Unlikelihood answered 14/5, 2019 at 11:10 Comment(0)
C
0

You should use Chocolatey as the Selenium wiki dictates. It will work straight away.

Windows users with Chocolatey installed: choco install chromedriver

https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver

Crest answered 29/5, 2019 at 21:54 Comment(0)
F
0

I also encountered the same problem. Following fix, made my application run smoothly.

Firstly, the required version of chrome driver could be found from below link.

http://chromedriver.storage.googleapis.com/index.html

It is best to use always the latest version. After downloading, set the path of chrome driver in System.setProperty("webdriver.chrome.driver","{Your path Chrome Driver}");

Follow the code fragment.

        System.out.println("Creating Chrome Driver");
     // Set Chrome Driver
        System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");

        WebDriver driver = new ChromeDriver();
        driver.get("{Your URL}");
        System.out.println("Wait a bit for the page to render");
        TimeUnit.SECONDS.sleep(5);
        System.out.println("Taking Screenshot");
        File outputFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        String imageDetails = "D:\\Images";
        File screenShot = new File(imageDetails).getAbsoluteFile();
        FileUtils.copyFile(outputFile, screenShot);
        System.out.println("Screenshot saved: {}" + imageDetails);
Foveola answered 4/11, 2019 at 6:57 Comment(0)
Z
0

In my case it wasn't working until I appended ".exe" instead of just "msedgedriver" i.e. (D://Java//edgedriver_win64//msedgedriver.exe). It's weird behavior for Edge because for firefox you don't need to mention ".exe"

Zebrawood answered 23/3, 2023 at 17:41 Comment(0)
E
0

All u need if you are using window is to replace this System.setProperty("webdriver.chrome.driver", "C:\chromedriver_win32");

with this line of code

System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");
Ephraimite answered 18/4, 2023 at 7:34 Comment(0)
W
-1

I faced the same issue. "The path to the driver executable must be set by the webdriver.chrome.driver system property." downloaded the driver and have set in system property.

https://www.youtube.com/watch?v=Ny_8ikCbmcQ

Wive answered 13/5, 2020 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.