0

I'm new to Selenium and I can't run the simplest program:

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

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

    HelloWorld.LOGGER.info(driver.getTitle());
}

The error I receive :

Exception in thread "main" 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:754)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(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.genesys.testing.topicsDefinitionUI.HelloWorld.main(HelloWorld.java:20)

After reading the exception above I saw in this website a solution that didn't work for me :

public static void main(String[] args) {
    System.setProperty("WebDriver.Chrome.driver","/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome");

    WebDriver driver = new ChromeDriver();

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

    HelloWorld.LOGGER.info(driver.getTitle());
}

The error I received :

Exception in thread "main" 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:754)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(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.genesys.testing.topicsDefinitionUI.HelloWorld.main(HelloWorld.java:20)

I'm working on MacOS - Catalina, my IDE is Intellij and this is a Maven Project.

Tried to switch the second argument of System.setProperty() function to numerous variations of the path with no success.

What am I missing ?

fuggerjaki61
  • 822
  • 1
  • 11
  • 24
Raziv
  • 59
  • 5

2 Answers2

0

To run your code on chrome browser you need to set path of chromedriver. ypu haavee specified wrong path of chrome driver in your code

System.setProperty("webdriver.chrome.driver","chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://google.com");
System.out.println(driver.getTitle());

Check your browser version and download chromedriver from the below link:

https://chromedriver.chromium.org/downloads

SeleniumUser
  • 4,065
  • 2
  • 7
  • 30
  • Downloaded it and received : Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. – Raziv Mar 23 '20 at 11:47
0

So, my friend here above @Rock was right.

I did need to download the chrome driver.

But, because I'm working on macOS Catalina, I had to change the permission for the chromedriver file manually.

With the help from this issue : MacOS Catalina(v 10.15.3): Error: “chromedriver” cannot be opened because the developer cannot be verified. Unable to launch the chrome browser

This is how the code looks like now :

    public void firstTest() {
        System.setProperty("webdriver.chrome.driver","/Users/raziv/Downloads/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.get("http://google.com");
        System.out.println(driver.getTitle());
    }

And it's working fine

Raziv
  • 59
  • 5