Java Selenium ChromeDriver executable does not exist - java

I looked everywhere and I don't know what am I doing wrong here. It would be really helpful if you could guys help me out.
Code:
System.setProperty("webdriver.chrome.driver","/Users/eshanmostafa/eclipse-
workspace/TestNG/chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().window().fullscreen();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(40,TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(40,TimeUnit.SECONDS);
}
Error Message:
FAILED CONFIGURATION: #BeforeMethod setUp
java.lang.IllegalStateException: The driver executable does not exist: /Users/eshanmostafa/eclipse-workspace/TestNG/chromedriver
at com.google.common.base.Preconditions.checkState(Preconditions.java:585)
at

Are you using macbook? you need to change driver exe file as executable file then refresh project and try again

Related

Exception in thread "main" java.lang.IllegalStateException: The driver executable must exist error using Selenium and Java

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:
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:
java.lang.IllegalStateException: The driver executable does not exist: while trying to execute tests through Selenium, ChromeDriver and Chrome

Can somebody explain why Selenium simple program is not working ? (On Mac using Maven-Java)

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 ?
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
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

Unable to find Matching Set of Capabilities and ChromeDriver

Here is the situation. I downloaded the chrome webdriver, unzipped the file, and went through the steps for setting the path through system properties. I am still unable to open chrome from Eclipse. Please help.
Unable to find matching set of capabilities
You are giving wrong parameter in system properties
Gecko driver is for firefox
If you have already downloaded chrome driver simply replace geckodriver.exe with chromedriver.exe.Otherwise, Download chrome driver and place it in your folder given in system properties and run your code.
Your code will appear as:
System.setProperty("webdriver.chrome.driver", "C:\\Users\\...\\Drivers\\chromedriver.exe");
// **Note**: complete your path above
driver = new ChromeDriver();

java.lang.IllegalStateException: The driver executable does not exist: C:\Users\jagrelot\workspace\AntBuildExample\chromedriver.exe with ChromeDriver

When I try to run Selenium within Eclipse, I get a The driver executable does not exist: error. I've ensured that the path to the exe is correct and that the environment PATH variable is set. The error is referencing an older location of the driver which was located in the workspace of the Java project. It seems to be working when I run it through the command line. Are there any suggestions to get the code to run in Eclipse properly?
public WebDriver chromeDriver;
#BeforeTest
public void beforeTestsetUp(){
System.setProperty("webdriver.chrome.driver", "C:\\Driver\\chromedriver.exe");
chromeDriver = new ChromeDriver();
[RemoteTestNG] detected TestNG version 6.12.0
FAILED CONFIGURATION: #BeforeTest beforeTestsetUp
java.lang.IllegalStateException: The driver executable does not exist: C:\Users\jagrelot\workspace\AntBuildExample\chromedriver.exe
The code block you have provided is not sufficient to analyze the root cause. How ever the following points are pretty much evident :
The initialization of ChromeDriver is error prone, it should have been :
ChromeDriver driver = new ChromeDriver();
As per best practices we should use the WebDriver interface instead of the ChromeDriver implementation :
WebDriver driver = new ChromeDriver();
As you are seeing the error as IllegalStateException: The driver executable does not exist: C:\Users\jagrelot\workspace\AntBuildExample\chromedriver.exe which clearly indicates your script is looking for the chromedriver binary in a different location other than the mentioned one. Probably its due to error prone code of setProperty.

IE Browser using Selenium Webdriver: "The driver executable is a directory"

I am getting the following error while trying to launch an IE browser using Selenium Webdriver. What seems to be the problem?
Exception in thread "main" java.lang.IllegalStateException: The driver executable is a directory: D:\Bhavesh\Bhavesh_Data\Study\Selenium\IEDriverServer_x64_2.45.0
at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:119)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:112)
at org.openqa.selenium.ie.InternetExplorerDriverService.access$1(InternetExplorerDriverService.java:1)
at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.build(InternetExplorerDriverService.java:247)
at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:251)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:172)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:146)
at first.IEDriver.main(IEDriver.java:11)
As per my understanding, when you set property for IEDriver location, you did not mentioned the full path (full directory path including iedriver exe)
For example.. Consider the following..
if you placed your IEDriverServer.exe in "D:/IEdriver" , then you have to set the property as follows:-
Right Approach:- System.setProperty("webdriver.ie.driver", "D:/IEdriver/IEDriverServer.exe");
Wrong approach :- System.setProperty("webdriver.ie.driver", "D:/IEdriver");
Let me know if it helps
I think there might be an issue in setting up the executable property..
Set the executable property as below
File file = new File("C:/Seleniumjars/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
driver = new InternetExplorerDriver();
}
Check path to driver, click on driver by right button in IDE and copy path to folder
Try to change path to something like this (with backslashes):
System.setProperty("webdriver.chrome.driver",
new File("C:\\QA\\neoAutomation\\src\\main\\resources\\drivers\\chromedriver.exe")
.getAbsolutePath());
return new ChromeDriver(getCapabilities(browser));
Add one folder and add all the drivers needed.
Now copy the path of the driver from properties and use it in set property example.
System.setProperty("webdriver.chrome.driver","C:\\Users\\arumugam\\eclipse-workspace\\FirstTestNG\\driversdirector\\chromedriver.exe");

Categories