I am getting this error:
"Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created exception"
i have updated my chrome and driver also to latest version.but still getting same error.
package helloworld;
public class testfb {
public static void main(String[] args) {
System.setProperty("webDriver.ChromeDriver", "C:\\minal\\drivers\\ChromeDriver.exe ");
// TODO Auto-generated method stub
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
}
}
chrome driver system property is case sensitive.
use this:
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
Related
public class Login
{
static WebDriver driver = new ChromeDriver();
#SuppressWarnings("resource")
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\MMFD-3\\MYData\\chromedriver.exe");
String baseUrl = "https://stackoverflow.com/";
driver.get(baseUrl);
}
}
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: 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:32)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at newpacakge.Login.(Login.java:14)
You are creating an instance of ChromeDriver before setting the property. Can you try after making following changes:
public class Login
{
static WebDriver driver;
#SuppressWarnings("resource")
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\MMFD-3\\MYData\\chromedriver.exe");
driver = new ChromeDriver();
String baseUrl = "https://stackoverflow.com/";
driver.get(baseUrl);
}
}
And make sure the chrome driver version is matching with your chrome version
This error message...
Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: 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.
...implies that your program was unable to locate the chromedriver excutable.
Seems you were pretty close. Within the class defination, you can of coarse declare the WebDriver instance as follows:
static WebDriver driver;
But you mustn't instantiate it as you did:
static WebDriver driver = new ChromeDriver();
Unless you specifically mention the absolute path of the chromedriver executable.
Solution
You need to separate the initialization part from the declaration:
static WebDriver driver;
Initialize the webdriver as a instance of ChromeDriver() later as follows:
System.setProperty("webdriver.chrome.driver","C:\\Users\\MMFD-3\\MYData\\chromedriver.exe");
String baseUrl = "https://stackoverflow.com/";
driver = new ChromeDriver();
driver.get(baseUrl);
I have applies the all code & still getting error to open chrome browser in selenium. I have set the property also for gecko-driver. pls check the code & give some solution
I am getting this 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:847)
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.(ChromeDriver.java:123)
at hps1.HPS.main(HPS.java:10)
HPS.java
package hps1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class HPS {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver=new ChromeDriver();
//System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");
// Open
driver.get("http://www.facebook.com");
// Maximize browser
driver.manage().window().maximize();
}
}
You are initializing driver first and then setting the system property thats why it is throwing an error. Moving the Property setting line above the driver initialization will do the job for you.
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
// Open
driver.get("http://www.facebook.com");
// Maximize browser
driver.manage().window().maximize();
}
Look,this is the first step,you should tell where the driver is and what type it is.
System.setProperty("webdriver.chrome.driver", "D:\\browser_driver\\chromedriver\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless"); //谷歌浏览器无头模式
// chromeOptions.addArguments("no-sandbox");//禁用沙盒
driver= new ChromeDriver(service,chromeOptions);//使用端口
And then build a new ChromeDriver is ok.You see the exception message tells you that the driver is not set well,so you should set it first and then construct a object later.
I'm creating tests(ui tests) on windows 10 machine. They works well, but few days ago my boss told me that we need to run our tests on linux. I'm downloaded linux driver and change it in System.setProperty("webdriver.chrome.driver", "chromedriver"); but after trying to run this test i got java.lang.ExceptionInInitializerError(it was latest driver with latest browser). After it i changed my code that allow me to run test, but connection to driver is remote. I don't like this way. May be some one of you know which driver will work on linux without code change in driver initialization part?
E.g.
windows driver initialization :
private static WebDriver driver = new ChromeDriver();
private static WebDriverWait wait = new WebDriverWait(driver, 30);
#Given("^blah blah$")
public void some_method() {
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
}
linux driver initialization :
public abstract class InitDrivers{
private static DesiredCapabilities capability = DesiredCapabilities.chrome();
public static WebDriver driver;
static {
try {
driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"),capability);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
public static WebDriverWait wait = new WebDriverWait(driver, 30);
public class CallDoctorTestStep extends InitDrivers{
#Given("^blah blah$")
public void some_method() throws MalformedURLException{
//System.setProperty("webdriver.chrome.driver","chromedriver.exe");
}
See solution in Selenium NoSuchSession on linux
java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError implies that an unexpected exception has occurred in a Static Initializer. This error is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable.
An ExceptionInInitializerError is raised if something goes wrong in the static initializer block. An example below :
class Anton
{
static
{
// if something goes wrong ExceptionInInitializerError will be thrown
}
}
Static variables are initialized in static blocks and can throw these errors.
Problem :
In your Linux Driver Initialization code block, initially you have mentioned :
private static DesiredCapabilities capability = DesiredCapabilities.chrome();
Then invoked the RemoteWebDriver as follows :
driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"),capability);
But in the following steps you have again tried to :
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
This sequence of events creates the error.
Solution :
As you have already declared the WebDriver instance as :
public static WebDriver driver;
Next, use System.setProperty() :
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); // <- remove the .exe part here following Linux style
Now you need to initialize the RemoteWebDriver instance as follows :
driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"),capability);
As the WebDriver instance (which is static) and Web Browser instance is active now you must not change the attributes during the Test Execution.
Note : You can find a detailed discussion in exception in initializer error
I'm using Firefox 45.8.0 version and I tried below code to open Firefox browser but i'm getting error that: "The path to the driver executable must be set by the webdriver.gecko.driver system property".
Please sagest me how to set the path.
Note:gecko driver will work for above firefox version 48.
package First;
import org.openqa.selenium.firefox.FirefoxDriver;
public class City {
public static void main(String[] args) {
// TODO Auto-generated method stub
FirefoxDriver c1=new FirefoxDriver();
c1.get("http://google.com");
}
}
Try this below code.
In your code you were not provide gecko driver path. You can download gecko driver from this link
public class City {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Drivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.get("http://google.com");
}
}
Here is the error:
[11762:11762:0801/141204:ERROR:url_pattern_set.cc(240)] Invalid url
pattern: chrome://print/*
getrlimit(RLIMIT_NOFILE) failed
[11762:11886:0801/141205:ERROR:get_updates_processor.cc(243)] PostClientToServerMessage() failed during GetUpdates
getrlimit(RLIMIT_NOFILE) failed
Code :
public class FirstTestCase {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "/usr/bin/google-chrome");
WebDriver driver = new ChromeDriver();
String URL = "mail.google.com";;
There are two problem in your provided code :-
You are setting webdriver.chrome.driver with installed chrome location which wrong. you need to download latest chrome driver zip from here and put at any location in your machine and extract that zip and set found chromedriver to the system property with variable webdriver.chrome.driver.
You are providing wrong URL to launch, You should provide URL with http:// or https://.
So the working example are as below :-
public class FirstTestCase {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "path/to/downloaded chromedriver");
WebDriver driver = new ChromeDriver();
String URL = "https://www.google.com";
driver.get(URL);
}
}
Hope it works..:)