org.openqa.selenium.SessionNotCreatedException: session not created exception - selenium

I'm trying to run some Selenium tests using the ChromeDriver, and I started getting this error:
Starting ChromeDriver 2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129) on port 42985
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"7576.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=54.0.2840.59)
(Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.48 seconds
Build info: version: 'unknown', revision: '2aa21c1', time: '2016-08-02 14:59:43 -0700'
System info: host: 'SUJITH', ip: '192.168.43.228', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.chrome.ChromeDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:683)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:143)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:170)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:159)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
at Selenium.Test2.main(Test2.java:15)
Why is this happening, and how can I fix it?

Update your chromedriver with lastest version. And please clarify your question.
https://chromedriver.storage.googleapis.com/index.html?path=2.24/

If your chrome browser is recently updated to V54.0.x, then you might get this error. The solution for this problem is simply to update your chrome driver.
Choose chrome driver from the below link that will suit your system architecture.
Latest Chromedriver v2.25

This issue started showing up after chrome Version 54.0.x updates.
Remove the older chromedriver from your path and update your chromedriver to 2.24. This should resolve your issue.

I had the same issue . Updating the chrome driver solved my problem.

A few things to bare in mind for these type of cases:
Disable browsers auto update - at least on your slaves to avoid these type of breaking your CI process. Link for how to on Chrome, and be sure to watch these settings on the installation.
Versioning is the first thing to check with Selenium when it breaks all of a sudden. See notes for version compatibility.
I'm using my own Maven plugin to check compatibility between chromedriver and Chrome version
Hope it helps...

You might be using the lower version of the chrome driver.
org.openqa.selenium.SessionNotCreatedException: session not created exception
I had the similar issue and was getting the exception as above. So always check the latest version of driver from here: https://sites.google.com/a/chromium.org/chromedriver/downloads

You might need to set in /etc/hosts
127.0.0.1 localhost

In my case the problem was that I kept a Selenium script running for too much time than I run out of disk free space.
So, I just clean out the Temp folder and created a routine to keep cleaning selenium folders, and problem solved.

You will get this error when your code looks like below:
WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
You have to setProperty first and then create driver instance next
System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

Related

How to solve "Your Firefox profile cannot be loaded. It may be missing or inaccessible" while using Selenium

I want to use selenium with geckodriver. So I have installed firefox and Geckodriver. But when I just run a simple selenium Application I get a dialoge box with the error.
My Code:
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver");
WebDriver driver2 = new FirefoxDriver();
driver2.get("https://google.com");
Selenium Log:
mozrunner::runner INFO Running command: "/usr/bin/firefox" "--marionette" "-no-remote" "-profile" "/tmp/rust_mozprofileBF85Lf"
Exception in thread "main" org.openqa.selenium.WebDriverException:
Process unexpectedly closed with status 1 Build info: version:
'3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:42:16' System
info: host: 'my-thinkpad', ip: '192.168.100.117', os.name: 'Linux',
os.arch: 'amd64', os.version: '5.15.0-33-generic', java.version:
'13.0.2' Driver info: driver.version: FirefoxDriver
But the main Problem I get as dialogbox:
Your Firefox profile cannot be loaded. It may be missing or
inaccessible.
When I just run the /usr/bin/firefox ... command in terminal without the profile parameter it works. I got the tip from several tutorials to delete the .mozilla directory in my home directory, but there is no .mozilla folder. Im using Kubuntu 22.04. Is there any way to start geckodriver without profile parameter or solve this problem?
Probably the profile gets stored in the directory where there is no permission to write. So, it would obviously fail.
Solution:
enter export TMPDIR=$HOME/Downloads/ geckodriver
In my case, my geckodriver is in Downloads so I exported TMPDIR to the Downloads.
Or try this:
Just move the geckodriver to any other directory where there is permission to write like Downloads or Documents and try the above solution.

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died with ChromeDriver and Selenium

I'm running a bunch of test cases every hour using selenium-java 3.12.0; TestNG; Selenoid with docker, Jenkins.
Sometimes (about 1 out of 10 cases) I get the error:
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'autotest.rvkernel.com', ip: '94.130.165.217', os.name: 'Linux', os.arch: 'amd64', os.version: '4.13.0-26-generic', java.version: '1.8.0_181'
Driver info: driver.version: RemoteWebDriver
Capabilities [{mobileEmulationEnabled=false, hasTouchScreen=false, platform=LINUX, acceptSslCerts=false, acceptInsecureCerts=false, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, platformName=LINUX, setWindowRect=true, unexpectedAlertBehaviour=, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.39.562737 (dba483cee6a5f15e2e2d73df16968ab10b38a2bf), userDataDir=/tmp/.org.chromium.Chromium.gURWcu}, takesHeapSnapshot=true, pageLoadStrategy=normal, unhandledPromptBehavior=, databaseEnabled=false, handlesAlerts=true, version=67.0.3396.62, browserConnectionEnabled=false, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}]
Session ID: 56c4b100a95d89b3d5702ec8a1a0698a
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:564)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:276)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement$1.invoke(EventFiringWebDriver.java:376)
at com.sun.proxy.$Proxy14.click(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.click(EventFiringWebDriver.java:389)
at com.Elements.Element.lambda$click$2(Element.java:99)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
at com.Elements.Element.click(Element.java:98)
at com.Elements.Element.click(Element.java:78)
at com.pages.landing.social.MailRuRegisterPage.clickRegister(MailRuRegisterPage.java:37)
at RulVulaknTests.authorization.AuthorizationTest.authorizationUserFromMailRU(AuthorizationTest.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:571)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: Cannot decode response content:
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:83)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
... 28 more
Caused by: org.openqa.selenium.json.JsonException: java.io.EOFException: End of input at line 1 column 1 path $
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'autotest.rvkernel.com', ip: '94.130.165.217', os.name: 'Linux', os.arch: 'amd64', os.version: '4.13.0-26-generic', java.version: '1.8.0_181'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.json.JsonInput.execute(JsonInput.java:172)
at org.openqa.selenium.json.JsonInput.peek(JsonInput.java:72)
at org.openqa.selenium.json.JsonTypeCoercer.lambda$null$6(JsonTypeCoercer.java:136)
at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:122)
at org.openqa.selenium.json.Json.toType(Json.java:62)
at org.openqa.selenium.json.Json.toType(Json.java:52)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
... 31 more
Caused by: java.io.EOFException: End of input at line 1 column 1 path $
at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1401)
at com.google.gson.stream.JsonReader.consumeNonExecutePrefix(JsonReader.java:1576)
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:534)
at com.google.gson.stream.JsonReader.peek(JsonReader.java:425)
at org.openqa.selenium.json.JsonInput.lambda$peek$0(JsonInput.java:73)
at org.openqa.selenium.json.JsonInput.execute(JsonInput.java:168)
... 37 more
And after this error all remained tests are skipped.
Versions of chrome browser using which I have encountered the error - 66, 67.
This error message...
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
...implies that the RemoteWebDriver instance was closed abruptly.
Your code trials would have been of some help to debug the issue. Perhaps yout main issue can be one of the following:
You have mentioned that you are using selenium-java 3.12.0 but your error trace logs mentions about selenium-java 3.6.0. So possibly there are multiple instances of selenium-java referenced within this project. So you need to ensure that your project is configured with only one set of selenium-java binaries.
As per best practices:
Upgrade Selenium to current levels Version 3.14.0.
Upgrade ChromeDriver to current ChromeDriver v2.41 level.
Keep Chrome version between Chrome v66-68 levels. (as per ChromeDriver v2.41 release notes)
(WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
(LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
As you have mentioned running a bunch of test cases every hour possibly there are multiple dangling instances of ChromeDriver and Chrome which can be viewed through the process list (Linux OS) or TaskManager (Windows OS). You need to always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
If the dangling instances of WebDriver and Web Browser still persists consider killing them with brute force. You can find a detailed discussion in Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?
Incase you program is attempting to set up TCP connections from ports that are greater than 5000 you can refer this article
References
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Getting "Error communicating with the remote browser. It may have died." with chromedriver
IE11: UnreachableBrowserException: Error communicating with the remote browser. It may have died.
WebDriver fix for UnreachableBrowserException
sorry for the reply to very old questions, but thought it could help someone else.
I was facing the same problem, and earlier I also thoughts issue is with Webdriver but it was not the case,
public static final Target EMAIL = Target.the("email")
.locatedBy(("//input[(#id='login-email-input')]"));
And everything was working fine with,
actor.attemptsTo(Enter.keyValues("someemail#gmail.com")
.into(EMAIL).thenHit(Keys.TAB));
but I thought to clear the input box before enter the new value and replaced above line with,
actor.attemptsTo(Clear.field(EMAIL));
actor.attemptsTo(Enter.keyValues("someemail#gmail.com")
.into(EMAIL).thenHit(Keys.TAB));
And I got the same error. After removing newly added line, things started working correctly.

How to connect Selenium Webdriver to existing Firefox/Chrome browser session?

This might be a repeated question but I could not find any solution. Recently I found a related post Connecting Selenium WebDriver to an existing browser session but people suggested me to ask a new question.
If any one have tried connecting selenium webdriver to existing browser session that was earlier spawned by selenium itself and had success in doing so, please let me know.
I could find couple of suggestions to try on firefox and selenium 2.X version. But those suggestions do not work for selenium 3.X and there are no solutions for chrome browser.
I have tried all suggestions for Selenium 25.3, firefox v 46 and it works. But for Chrome with chrome driver , I am not able to make it work.
Edited:
Here is the code I have tried:
Starting a firefox driver
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"/StartFirefoxSession_lib/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
Copied RemoteWebDriver source code and changed capabilities from private to protected.
protected Capabilities capabilities;
Created a new class RemoteDriverEx extending the copied RemoteWebDriver class
Changed the NEW_SESSION command issued by the original driver to GET_CURRENT_URL
Response response = execute(DriverCommand.GET_CURRENT_URL, Collections.EMPTY_MAP);
Then craeted a JUnit test to verify
But I am struck with exception
org.openqa.selenium.WebDriverException: No command or response codec has been defined. Unable to proceed
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'WPANDBW7HYD', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_74'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:154)
Full code shared # https://drive.google.com/open?id=0Bz2XxuQQc24KdHVqR3BPaXowUnM
It is possible in selenium all you need is a debugger address of the session you want to connect to. If you are wondering what is debugger address its nothing but the localhost address on which your session is running, it looks like localhost:60003. Now it will be different for each and every case. Below is process with c# code.
Get debugger Address of browser you want to connect later using debug mode as shown in snapshot below. debug driver after browser launch to fetch value
Now keep that browser running and to reconnect the same browser use below code.
ChromeOptions option = new ChromeOptions();
option.DebuggerAddress="localhost:60422";// we need to add this chrome option to connect the required session
driver = new ChromeDriver(option);
driver.Navigate().GoToUrl("https://www.google.com/");
Hope this helps!! let me know in comments if any clarification is required.
I managed to find a solution for Firefox in a hack way that works local:
First, you need to start a separate instance of browser (manual start) using the following arguments:
firefox.exe --marionette -profile C:\FirefoxTEMP
Above we open an instance of Firefox with --marionette turned on and we choose a fixed profile folder that were created just for selenium tasks.
Now, we will attach our automation to the already open Firefox window, by adding an argument to chose the same profile we started before.
Note: You must chose the same profile folder for the Webdriver use the open instance.
FirefoxOptions options = new FirefoxOptions();
options.AddArguments("--profile C:\\FirefoxTEMP");
driver = new FirefoxDriver(options);
driver.Navigate().GoToUrl("https://google.com");

Selenium 2.47 doesn't work with Firefox v31

I am using selenium 2.47 with Firefox v31. With this simple implementation:
public void navigateToHomePage() throws Throwable {
System.out.println("Navigate to Home");
driver = new FirefoxDriver();
driver.quit();
}
I got this error:
org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms
Build info: version: '2.47.0', revision: '0e4837e', time: '2015-07-29 22:49:49'
System info: host: 'ok-ThinkPad-SL500', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.7.0_79'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.internal.SocketLock.lock(SocketLock.java:99)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:90)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:276)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:116)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:223)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:212)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
at cucumber.features.StepDefinitions.navigateToHomePage(StepDefinitions.java:24)
at ✽.Given I navigate to the home site(/home/ok/workspace/CucumberPOC/src/cucumber/features/UserRegistry.feature:6)
I don't know what is it??
This SocketLock error happens when Firefox tries to bind to port 7054 and fails because another instance already has that port locked.
An immediate solution is make sure you have NO Firefox tasks or process running in the background before launching a new driver. Kill them all and try launching again.
In the long run, you can avoid these issues by creating a new profile, change the port preferences to avoid locks, and then launch the driver using that profile. A short example:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(FirefoxProfile.PORT_PREFERENCE, 7046)
driver = new FirefoxDriver(profile);
Unfortunately, when I was looking up the Java terms, I found that this feature was broken in Java's driver once, then it was fixed and then it broke in a later update, so even if you implement the solution I gave you, you may still get these errors in 2.47.
The fix was released in version 2.43.1, so if you don't need the newer versions for another issue/feature, you can try rolling back to a point where you can set a port preference successfully.
Not required reading: Some more technical details of the issue are in this pull request.

getting exeception while using chrome browser in selenium project

I am using chrome browser in selenium project.
Here is the user agent string that I am using:
System.setProperty("webdriver.chrome.driver","C:\\users\\..\\chromedriver.exe");
driver = new ChromeDriver();
What happens IF I run the script:
It open the chrome browser and after some time it close it and giving error:
org.openqa.selenium.WebDriverException: unknown error: unable to
discover open pages (Driver info: chromedriver=2.2,platform=Windows
NT 6.1 x86) (WARNING: The server did not provide any stacktrace
information) Command duration or timeout: 26.83 seconds Build info:
version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'QAVM-9', ip: '27.101.1.26', os.name: 'Windows 7',
os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45' Driver
info: org.openqa.selenium.chrome.ChromeDriver at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at
org.openqa.selenium.chrome.ChromeDriver.startSession(ChromeDriver.java:182)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:115)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:161)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:150)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:139)
Please help me, It completely stop the execution.
Let me know in case need any other information.
I would suggest you to update your chrome driver since your version is 2.2 and the latest is 2.9. It might be possible that your existing chrome driver might not be supporting your chrome browser if the browser is of latest version.
Chrome driver versions are here
Also check the release notes here. Each chromedriver mentions which chrome browser versions
it supports.
Here's what I did to get rid of that error (
unknown error: unable to discover open pages
)
In your protractor config file, add the following:
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--no-sandbox']
}
},
The most important line there is the --no-sandbox; adding that line somehow gets rid of that error.
I am not exactly sure why it works but it's a workaround I found while digging around online.