I am running the following but getting the error
public class base
{
public static WebDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\code\\lib\\browser drivers\\chromedriver.exe");
String URL = "http://www.google.com";
String Node = "http://localhost:4444/wd/hub";
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap = DesiredCapabilities.chrome();
cap.setPlatform(org.openqa.selenium.Platform.WINDOWS);
driver = new RemoteWebDriver(new URL(Node), cap);
driver.navigate().to(URL);
Thread.sleep(5000);
driver.quit();
}
}
Error shown is as follows :
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: ChromeDriverService
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'RAJESHW10', ip: '169.254.3.253', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: driver.version: unknown
Command duration or timeout: 316 milliseconds
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Can somebody please help
The error does gives us a hint about what is going wrong as follows :
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: ChromeDriverService : Unable to create new service: ChromeDriverService which means the new session wasn't initiated.
Driver info: driver.version: unknown : driver.version: unknown means the chromedriver binary wasn't invoked at all.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) : sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) which stems out from either of the following :
java.lang.RuntimeException: exception in constructor : Occurance of this exception is unique to reflection. Normally, it is impossible to write code which ignores a checked exception as it would not compile at all.
java.lang.reflect.InvocationTargetException : If an InvocationTargetException is thrown that means the method was invoked. This exception does not indicate a problem with the reflection package or its usage.
java.lang.IllegalArgumentException : An IllegalArgumentException is thrown if the constructor was passed an argument of the wrong type.
Conclusion
From the above mentioned ponints it is pretty clear that the version of Selenium-Java client, JDK, ChromeDriver binary and Chrome are not compatible.
Solution
The solution would be as follows :
Update your JDK with the recent releases (JDK 8u152)
Update your Selenium-Java client with the recent releases (Selenium-Java v3.8.1)
Update your ChromeDriver binary with the recent releases (ChromeDriver v2.34)
Update your ChromeDriver binary with the recent releases (Chrome v63.0)
Please do the following and retry.
Ensure that the path C:\\code\\lib\\browser drivers\\chromedriver.exe is added to your %PATH% variable on the machine in which you are running the node. This would ensure that the selenium uber jar can find the location of the chromedriver binary.
System.setProperty("webdriver.chrome.driver", "C:\code\lib\browser drivers\chromedriver.exe");
This mechanism should be only used when you are doing
ChromeDriver driver = ChromeDriver()
Since you are working with a selenium grid, you are dealing with multiple JVMs here.
System.setProperty() will affect only the current JVM (which in this case is your tests), but the actual browser gets spun off in a different JVM (the one that is running the selenium node).
Related
I'm using Selenium Web driver, however, I am preloading a browser by setting the debuggerAddress. I connect through a specified port. I had this working great. Suddenly, it's stopped working. I'm not quite sure what the issue is.
public void launchBrowser() throws InterruptedException {
try {
// Set file path of chrome driver
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
// Start chrome driver with existing chrome browser
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("debuggerAddress","localhost:1250");
// Create object
driver = new ChromeDriver(options);
// Write to console where we are
System.out.println(driver.getCurrentUrl());
}
catch(Exception e) {
console("JacksClass.java","launchBrowser()", "Exception: " + e);
}
}
Before I run the script. I start the Chrome browser with this command in CMD
start chrome --remote-debugging-port=1250
After launching the browser from CMD successfully. Then running the code. I get the following exception after around 1-2 minutes.
JacksClass.java - launchBrowser() : Exception: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '4.0.0-alpha-6', revision: '5f43a29cfc'
System info: host: 'DESKTOP-5H32IOI', ip: '192.168.1.53', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.8'
Driver info: driver.version: ChromeDriver
All of this was working great a month ago. I have the chrome driver installed in the same location.
Finally got it to work. Firstly I tried to access the open port in another browser.
Typing localhost:1250 into the URL bar.
It could not connect. So there clearly was an issue with that port. I have tried many different ports but still had the same issue.
I finally tried port 1258 and then double-checked it with the test outlined above. Typing localhost:1258 into another browser proved the port was active.
Then my program worked as well! How strange! Glad it's working now :)
I have tried everything that has been told in Stackoverflow topics. I have java selenium tests run on remote slave through jenkins. The absurd thing is first test always run and browsers opens, all other tests give me "Timed out waiting for driver server to start".
public WebDriver startChrome() {
System.setProperty("java.net.preferIPv4Stack", "true");
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--disable-dev-shm-usage");
chromeOptions.addArguments("--aggressive-cache-discard");
chromeOptions.addArguments("--disable-cache");
chromeOptions.addArguments("--disable-application-cache");
chromeOptions.addArguments("--disable-offline-load-stale-cache");
chromeOptions.addArguments("--disk-cache-size=0");
chromeOptions.addArguments("--dns-prefetch-disable");
chromeOptions.addArguments("--no-proxy-server");
chromeOptions.addArguments("--log-level=3");
chromeOptions.addArguments("--silent");
chromeOptions.addArguments("--disable-browser-side-navigation");
chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
chromeOptions.addArguments("-disable-cache");
chromeOptions.addArguments("-disable-extensions");
chromeOptions.addArguments("--incognito");
chromeOptions.addArguments("start-maximized");
//chromeOptions.setExperimentalOption("useAutomationExtension", false);
ChromeDriverService chromeDriverService = ChromeDriverService.createDefaultService();
port = chromeDriverService.getUrl().getPort();
return new ChromeDriver(chromeDriverService, chromeOptions);
}
Error:
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '4.0.0-alpha-7', revision: 'de8579b6d5'
System info: host: 'ISTDTSTYNMD04V', ip: '10.52.253.54', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_271'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:231)
at org.openqa.selenium.remote.service.DriverService.lambda$start$0(DriverService.java:193)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1596)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1067)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1703)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:172)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:35592/status] to be available after 20000 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:90)
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:227)
... 7 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:205)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:88)
... 8 more
All the solutions I have tried so far:
Update Java 1_8_271
Update Selenium 4
Update ChromeDriver 87
Check localhost traffic with rawcap
Check localhost dns definiton in etc/hosts
Update Chrome 87
Set Proxy
Check port availability
Check driver path
Kill all chrome and driver tasks before create (Only solution that worked, but not good for parallel tests)
Check localhost url and port is accessible with chrome -> http 200
When I try to reach url and port through java urlconnection in code driver create function catch block), it gives me connection reset but in chrome it gives 200.
All help will be appreciated.
Best Regards
This error message...
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '4.0.0-alpha-7', revision: 'de8579b6d5'
System info: host: 'ISTDTSTYNMD04V', ip: '10.52.253.54', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_271'
Driver info: driver.version: unknown
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
A bit of more information about your usecase would have helped us to analyze the error in a better way. However to start with you can use only one single arguments start-maximized and remove all the other arguments which would get you started. So your effective code block will be:
public WebDriver startChrome() {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("start-maximized");
ChromeDriverService chromeDriverService = ChromeDriverService.createDefaultService();
return new ChromeDriver(chromeDriverService, chromeOptions);
}
Additional Consideration
Ensure that:
JDK is upgraded to current levels JDK 8u271.
Selenium is upgraded to current released Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v87.0 level.
Chrome is updated to current Chrome Version 87.0 level. (as per ChromeDriver v87.0 release notes).
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
References
You can find a couple of relevant detailed discussions in:
Selenium Chromedriver server times out despite being available
Driver info: driver.version: unknown with ChromeDriver Chrome using Selenium and Python
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start while initiating Chrome browser through Selenium
I have a Java Selenium project that will not run on my machine, but does run on coworkers' machines with the same OS version (OSX 10.13.1), Chrome browser version (63.0.3239.84), and chromedriver version (2.34). I get the message:
Starting ChromeDriver 2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e) on port 18633
Only local connections are allowed.
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'localhost', ip: 'fe80:0:0:0:1cc9:e0ab:f4e5:dd34%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.1', java.version: '1.8.0_20'
Driver info: driver.version: ChromeDriver
...
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:18633/status] to be available after 20005 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187)
... 28 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:205)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:149)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
... 29 more
however when I open http://localhost:18633/status in my browser I get a valid response:
{"sessionId":"","status":0,"value":{"build":{"version":"alpha"},"os":{"arch":"x86_64","name":"Mac OS X","version":"10.13.1"}}}
I've tried swapping out chromedriver binaries, but I'm not really sure what else to do. I get similar issues with geckodriver, but that may or may not be the same issue.
I have also tried creating a new user on my system and running it from that account, to account for user settings - No luck.
What am I missing here? What info would be helpful to debug this problem?
The error says it all :
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Clearly indicates the WebDriver instance didn't get initiated. Hence Driver info is left blank as :
Driver info: driver.version: ChromeDriver
Which inturn produces the error:
org.openqa.selenium.net.UrlChecker$TimeoutException
and
java.util.concurrent.TimeoutException
It would be tough to guess the actual reason without any visibility of your code block but in general we can solve this by downloading the ChromeDriver binary from this repository and passing the absolute path of the ChromeDriver while initializing the WebDriver instance as follows :
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
driver = new ChromeDriver();
Key Points :
Always use the latest version of the Selenium Client and ChromeDriver binaries.
Always keep the automatic updates for the browser enabled.
Always keep the JDK version updated (the current version being JDK 8u241)
I am receiving the following exception for my java code. All I want to do is open up a chrome browser. I have downloaded the proper chrome driver and stuck it in my google chrome folder under program files x86. Right now what happens is, the browser opens and then immediately says that the program has stopped working and then It throws the exception once I click exit on the window.
Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 23239
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'W7LPC01TDFU', ip: '10.95.7.58', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_79'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
here is my code so far
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class mainTester {
public static void main(String[] args) throws InterruptedException{
setUp();
}
public static void setUp() throws InterruptedException {
// Optional, if not specified, WebDriver will search your path for chromedriver.
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com/xhtml");
Thread.sleep(5000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
Thread.sleep(5000); // Let the user actually see something!
System.out.println("Finished");
driver.quit();
}
}
Do you know what version of Chrome you are using? Chances are the latest since Google likes to autoupdate. You should be using the latest version of Chromedriver. The traceback you posted says you are using version 2.20 (Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 23239). The latest is 2.25 which Supports Chrome v53-55
I'm very new to Selenium. Below given is my first test script.
Question: Does it require selenium server to test a local website (which is hosted in the same machine as the test scripts being run).
Also tried executing the same script from Internet Explorer also, still getting the same.
It just opens the browser and closes(because of finally block) it.
import org.openqa.selenium.chrome.ChromeDriver;
public class TestScript {
/**
* #param args
* #throws InterruptedException
*/
public static void main(String[] args) {
ChromeDriver driver = null;
try
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\user1\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
driver = new ChromeDriver();
System.out.println("Opening the Browser");
driver.get("http://localhsot:5080/myWebSite/8450191#");
System.out.println("Open the Browser");
System.out.println("");
System.out.println("Title" +driver.getTitle());
}
catch (Exception ie)
{
ie.printStackTrace();
}
finally
{
System.out.println("Quitting the Browser");
driver.close();
driver.quit();
}
}
}
Exception: Below is the exception I am getting while executing from the Eclipse:
[2820:6204:36503609:ERROR:gpu_info_collector_win.cc(93)] Can't retrieve a valid WinSAT assessment.
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: '01hw535163', ip: '10.72.15.53', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_17'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:112)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:116)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:162)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:108)
at com.seic.scripts.TestScript.main(TestScript.java:16)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: '01hw535163', ip: '10.72.15.53', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_17'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
... 6 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:37571/status] to be available after 20009 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
... 8 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
... 9 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:228)
at java.util.concurrent.FutureTask.get(FutureTask.java:91)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
... 10 more
Quitting the Browser
Exception in thread "Main Thread" java.lang.NullPointerException
at com.scripts.TestScript.main(TestScript.java:31)
Chrome Version: 21.0.1171.0
OS: Windows 7 64 bit.
Selenium Web Driver version:2.39.0
You are getting a little confused about what you need to point Selenium to.
Here:
System.setProperty("webdriver.chrome.driver", "C:\\Users\\user1\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
This setting, webdriver.chrome.driver is a setting that Selenium will read to find out where the ChromeDriver is located, not the actual Chrome installation.
https://code.google.com/p/selenium/wiki/ChromeDriver
You must download the ChromeDriver and where it is located should be what you pass in for the webdriver.chrome.driver property.
I imagine it's the same reason when you try with IE, it also requires a driver which I guess you don't have:
https://code.google.com/p/selenium/wiki/InternetExplorerDriver
In terms of whether you need a "server" -> for your tests, no, you are not running them remotely. Once you decide to run them remotely (i.e use the RemoteWebDriver instead of ChromeDriver) then you will need the Selenium server.
I would recommend instead of using System.setProperty() to put your drivers in the same folder and point to that folder in System Variables Path. Then you don't need to point to it at all in code and updating your driver won't require a code rewrite.