import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class App {
public static void main(String[] args) throws Exception {
System.out.println("hi");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
driver.quit();
}
}
I imported jar file for selenium and downloaded right webchrome drive and it give me error
PS D:\software testing task 2> & 'C:\Program Files\Java\jdk-17.0.1\bin\java.exe' '-XX: ShowCodeDetailsInExceptionMessages' '@C:\Users\mohamed\AppData\Local\Temp\cp_apvu20bu2lqgd550a094p3mwf.argfile' 'App'
zzzzzzzzzz
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 App.main(App.java:7)
CodePudding user response:
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);"
The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information:
System.setProperty("<Path to>chromedriver.exe");
CodePudding user response:
Absolute Path: System.setProperty("webdriver.chrome.driver","D:\List_of_Jar\chromedriver.exe");
Relative Path:
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") "./Driver\\chromedriver.exe");
Path to the driver must be set before webdriver object creation and check browser version and chromedriver version.