1

I am unable to execute my first selenium code. Tried changing webdriver path several times but that didn't work.

Code trials:

package Learningday1;

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

public class FirstScript {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "‪‪‪C:\\Users\\amann\\Downloads\\chromedriver_win32\\chromedriver.exe");
        WebDriver driver = new ChromeDriver(); 
        driver.get("https://selenium.dev");
        System.out.println(driver.getTitle());
        driver.quit();
    }

}

Error:

Exception in thread "main" java.lang.IllegalStateException: The driver executable must exist: C:\Users\amann\eclipse-workspace\Selenium learning 2.0\???C:\Users\amann\Downloads\chromedriver_win32\chromedriver.exe
    at org.openqa.selenium.internal.Require$FileStateChecker.isFile(Require.java:342)
    at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:147)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:142)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:39)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:233)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:437)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:128)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:49)
    at Learningday1.FirstScript.main(FirstScript.java:10)

Snapshot:

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Aman Nigam
  • 13
  • 1
  • 4
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 25 '22 at 09:28

1 Answers1

0

There is some ambiguity between your code trials and the error stacktrace.

In your code you mentioed the ChromeDriver as:

‪‪‪C:\\Users\\amann\\Downloads\\chromedriver_win32\\chromedriver.exe

Where as the error stacktrace mentions the driver executable doesn't exists at:

C:\Users\amann\eclipse-workspace\Selenium learning 2.0???C:\Users\amann\Downloads\chromedriver_win32\chromedriver.exe

Solution

Ensure that you have unzipped the ChromeDriver and placed with the sub-directory:

C:\\Users\\amann\\Downloads\\chromedriver_win32

and you need to mention the absolute path within the System.setProperty() line as:

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

Update

You have 2 projects with almost similar names, a maven project and another a Java project. The name starting with Selenium learning.

Try to avoid same name for multiple projects and blank spaces within the project names. Example SeleniumTest, SeleniumProgram, etc.

PS: You may opt to delete the current project and create a new one.


References

You can find a relevant detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Yes i had unzipped it and also checked again that it has been unzipped and there's no copy of it – Aman Nigam Jul 24 '22 at 22:12
  • but i created this project because the earlier one was too giving same error that had maven dependencies, and this one too giving same error i don't know why, please help – Aman Nigam Jul 25 '22 at 11:39
  • Possibly _blank spaces within the project name_ is causing all the issues. Delete the unwanted one. – undetected Selenium Jul 25 '22 at 11:40
  • 1
    Thank you so much dear, it worked. Thanks for the help, now i can learn selenium. Once again thank you. – Aman Nigam Jul 25 '22 at 12:04