Error in initialization of chrome browser in selenium webdriver [duplicate] - selenium-webdriver

This question already has answers here:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property
(4 answers)
Closed 4 years ago.
I executed below script in selenium webdriver:
package Facebook;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class facebooklogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver=new ChromeDriver();
driver.get("https://www.facebook.com");
driver.manage().window().maximize();
}
}
Facing below error:
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:172)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
at
org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
at
org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at
org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:290)
at
org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:116)
at Facebook.facebooklogin.main(facebooklogin.java:11)

Please check your exception lines, which is saying - java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property;
Selenium can't communicate directly with browsers, it needs a driver file which is provided by the browser providers. Here in Chrome browsers when you want to run the script you'll require chromedriver basically provided by Google. Downlaod the driver file and put it in your project, and add below lines before browser initialization.
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();

Related

ERROR : java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; [duplicate]

This question already has answers here:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property with Selenium GeckoDriver
(1 answer)
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property
(4 answers)
Mac OSX - IllegalStateException: The driver is not executable:
(12 answers)
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist while running Selenium Test on Ubuntu
(1 answer)
Closed 3 years ago.
I am unable to launch the browser through TestNG with Selenium 2.0.
Please look into the below code & need your kind assistance.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Annotations {
#Test
public void openBrowser(){
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
Please check your browser version as well. because selenium 2.X not support firefox 47+ versions.

"The driver is not executable" when I try to launch a chrome browser with Selenium [duplicate]

This question already has answers here:
Mac OSX - IllegalStateException: The driver is not executable:
(12 answers)
Closed 3 years ago.
I am getting this error.
Exception in thread "main" java.lang.IllegalStateException: The driver
is not executable: /home/hashconnect/Desktop/Priya
bugsheet/selenium/chromedriver.exe
Creating a new folder "Drivers" in that project and changed the location as ".\drivers\chromedriver.exe"
This is my code:
package demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class test {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","/home/hashconnect/Desktop/Priya bugsheet/selenium/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
Thread.sleep(5000);
}
}
Expected: System should launch the chrome browser
Actual:
It showing error message:
Exception in thread "main" java.lang.IllegalStateException: The driver
is not executable: /home/hashconnect/Desktop/Priya
bugsheet/selenium/chromedriver.exe
Go to task manager, close all instance of chrome browser by end task and it should work.
One reason could be that the path to the driver executable has got a space in it. A suggestion would be to move the driver to a different path and update the path in your code and retry.
Try doing a
"ls -ltr /home/hashconnect/Desktop/Priya bugsheet/selenium/chromedriver.exe"
Or it could be that there might be multiple instances of ChromeDriver already running and they are preventing the spawning of more instances. So the suggestion is to kill all those instances from the TaskManager on Windows or with kill -9 on linux.
The Problem is Path which you have given.
Try giving full path
Example: C:/Users//Desktop/...../chromedriver.exe
This will Solve your Problem.
Dry Ran it:
java.lang.IllegalStateException: The driver executable does not exist: C:\main\resources\chromedriver.exe
The Above Error occurs if you give invalid path (non relative path)
It Works:
C:\Users\SA\test\src\resources\chromedriver.exe
The driver is not executable : this issue might occur if the chromedriver.exe does not have execution permission
I am not sure how selenium works on Ubuntu. Still, the Set up you have downloaded seems to be for a windows version(.exe). It doesn't work on Linux.
Please download the chrome driver for Linux from the below link
Download Chrome Driver for Linux
Reference:
Reference link

Test case not running iin selenium webdriver

I tried to use the following code to open a URL in my local system. But I get error message as shown in screen shot.
Code
package First_test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class first_case {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
//Launch the Website
driver.get("http://127.0.0.1:3000");
// Print a Log In message to the screen
System.out.println("Successfully opened the website ");
// Close the driver
driver.quit();
}
}
error message
What shall I do to solve this problem? Thanx!
You need to install gecko driver. A brief introduction about it and how to install gecko driver can be found in following link. Hope this helps!
Gecko Driver is the link between your tests in Selenium and the Firefox browser
http://toolsqa.com/selenium-webdriver/how-to-use-geckodriver/
I installed gecko driver from github and put it in the folder location of my workplace and it worked!
working result
Download geckodriver and use this code:
System.setProperty("webdriver.gecko.driver", "E:/software and tools/geckodriver.exe");
WebDriver driver= new ChromeDriver();
//Launch the Website
driver.get("http://127.0.0.1:3000");
// Print a Log In message to the screen
System.out.println("Successfully opened the website ");
// Close the driver
driver.quit();

Unable to open chrome using Selenium

I am using the following code to run chrome driver:
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestClass
{
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", "/Users/raisa/Documents/Selenium/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
driver.quit();
}
}
But I am getting this error:
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: /Users/raisa/Documents/Selenium/chromedriver.exe
at com.google.common.base.Preconditions.checkState(Preconditions.java:177)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:117)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:112)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:117)
at TestClass.main(TestClass.java:11)
I have downloaded the latest chrome driver from http://chromedriver.storage.googleapis.com/index.html
I agree with the comments.
On Mac OS you will not need .exe after chromedriver.
For your example you'll want it to look like this: /Users/raisa/Documents/Selenium/chromedriver.
I've also seen this problem come up because the execute permissions wasn't set for the file.
So double check the file permissions, and also that the file is in the actual path given.
Through terminal navigate to the place where chromedriver is located and then execute following command.
xattr -d com.apple.quarantine chromedriver

Unable to launch Firefox driver

I have Firefox 11 in my Win7 system with selenium 24.1:
When I tried to launch Firefox using from Eclipse, I got following error(It's same for all even after re installation ):
**Exception in thread "main" java.lang.ExceptionInInitializerError
at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:389)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:89)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.fire fox.FirefoxDriver.<init>(FirefoxDriver.java:95)at mend.w.main(w.java:9)
Following is the code, I tried:
package try;
import org.openqa.selenium.firefox.FirefoxDriver;
public class trySelenium {
public static void main(String[] args) {
// TODO Auto-generated method stub
FirefoxDriver n = new FirefoxDriver();
n.get("google.com");
}
}
Since you are using selenium 2.41, it will not support Firefox 11. Either upgrade your browser or downgrade selenium version to respective supported Firefox version.
Instead of using:
FirefoxDriver n = new FirefoxDriver();
use following in your code:
WebDriver n = new FirefoxDriver();
WebDriver is an interface that FirefoxDriver class is implementing.

Resources