2

Here is my code:

package Basics;

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

public class invokegoogle {

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

    System.setProperty("Webdriver.chrome.driver", "C:\\Users\\sravani\\Desktop.exe");
    WebDriver driver=new ChromeDriver();
    driver.get("http://qaclickacademy.com");

    }

}

Getting the following errors:

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:124)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
    at Basics.invokegoogle.main(invokegoogle.java:12)

Any help is highly appreciated. Thanks in advance

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
sam
  • 31
  • 1
  • 1
  • 2
  • 1
    Possible duplicate of [How to run Selenium WebDriver test cases in Chrome?](https://stackoverflow.com/questions/13724778/how-to-run-selenium-webdriver-test-cases-in-chrome) – JeffC Oct 05 '17 at 15:30

4 Answers4

5

Assuming the chromedriver.exe is stored at your desktop, you need to make a couple of changes as follows:

  • You need to replace the uppercase W with lower case w within Webdriver.chrome.driver.
  • As you are on system, presuming chromedriver.exe is placed in your desktop ypu need to append the WebDriver variant name along with the extension within the absolute path of the WebDriver.
  • Effectively the line of code will be:

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

Note: webdriver.chrome.driver needs to start with lowercase letter.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

Once you download chrome driver into your system, after extracting it (unzipping it) into the folder, it looks like you have directly copied the folder path "Downloads/chromedriver_win32.exe", instead using full path as below mentioned

Open the folder (chromedriver_win32.exe), then you will see "chromedriver.exe" as .exe file, and use this path instead and it looks like this

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

This will work

Ram
  • 19
  • 3
1

Add your chrome driver to java resource folder

Driver location

Add the below mentioned code will work

System.setProperty("webdriver.chrome.driver", Objects.requireNonNull(getClass().getClassLoader().getResource("drivers/chromedriver.exe")).getFile() );
Vinayagam.D
  • 322
  • 3
  • 10
0

i also got same issue then searched so many answer and apply into my code but result showing null then after i realized that i had declare static variable on above of class looks like

private static WebDriver driver = new ChromeDriver(); 

then i rewrite code on under void main class like

WebDriver driver = new ChromeDriver(); 

now my code running works fine you can also try like this or let me know so i can help you.

Pankaj
  • 21
  • 10