0

Trying to learn Selenium , I opened the similar question but nothing seemed to help. My code

package seleniumPractice;

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

public class seleniumPractice {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();

        driver.get("https://google.com");

        driver.quit();
    }
}

My Errors :-

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable 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 https://chromedriver.storage.googleapis.com/index.html
    at org.openqa.selenium.internal.Require$StateChecker.nonNull(Require.java:311)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:135)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:38)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:231)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:437)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:127)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:48)
    at seleniumPractice.seleniumPractice.main(seleniumPractice.java:8)
Moaz El-sawaf
  • 2,306
  • 1
  • 16
  • 33
Rushil
  • 11
  • 5
  • What version are your OS, browser, java and Selenium? Please add this to the question and include from the start next time. Now to your problem: You have two options: Either add `System.setProperty("webdriver.chrome.driver", "C:\path\to\chromedriver.exe");` to your code (_lower case [is important](/q/44342565)_) or chromedriver.exe's parent directory to the PATH environment variable. It's the same procedure for Chromes as for Firefox in [Selenium using Java - The path to the driver executable must be set by the webdriver.gecko.driver system property](/q/38676719) – cachius May 21 '22 at 23:25

1 Answers1

1

It's the same issue as previous questions. Please add the following lines to your code changing "C:\stack\overflow\chromeDriver.exe" to the absolute path of your chromedriver.exe in your device.

 System.setProperty("webdriver.chrome.driver", "C:\\stack\\overflow\\chromeDriver.exe");
 WebDriver driver = new ChromeDriver();

Please note absolute paths follow the standard used in the answer here: How do I get the file name from a String containing the Absolute file path?

They require the double \ while windows will give you / if you copy the path from file explorer or similar. You need to replace each / with \ for things to work

This wouldn't be an issue if you had set up chromedriver as an system variable and pointed to your file. That is what my lines of code are doing.

dot
  • 64
  • 7