Issue
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.(ChromeDriver.java:48) at seleniumPractice.seleniumPractice.main(seleniumPractice.java:8)
Solution
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.
Answered By - user2304843
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.