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.
Related
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.
I am using Eclipse Luna with windows 10-64 bit, selenium-server-standalone-3.141.59 and selenium-java-3.141.59. I have write a simple program to hit the url .But I am getting this error:
[13552:3540:0515/184943.562:ERROR:cache_util_win.cc(21)] Unable to
move the cache: 0
[13552:3540:0515/184943.562:ERROR:cache_util.cc(141)] Unable to move
cache folder C:\Users\RChauh\AppData\Local\Google\Chrome\User
Data\ShaderCache\GPUCache to
C:\Users\RChauh\AppData\Local\Google\Chrome\User
Data\ShaderCache\old_GPUCache_000
[13552:3540:0515/184943.562:ERROR:disk_cache.cc(185)] Unable to create
cache [13552:3540:0515/184943.562:ERROR:shader_disk_cache.cc(623)]
Shader Cache Creation failed: -2 Opening in existing browser session.
Exception in thread "main" org.openqa.selenium.WebDriverException:
Timed out waiting for driver server to start. Build info: version:
'3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' System
info: host: 'LAPTOP-3VFBUTNB', ip: '192.168.1.102', os.name: 'Windows
10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_211'
Driver info: driver.version: ChromeDriver at
org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:202)
at
org.openqa.selenium.remote.service.DriverService.start(DriverService.java:188)
at
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:181)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:168)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at helloWorld.java.main(java.java:11) Caused by:
org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting
for [http://localhost:32149/status] to be available after 20016 ms at
org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
at
org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:197)
... 9 more Caused by: java.util.concurrent.TimeoutException at
java.util.concurrent.FutureTask.get(Unknown Source) at
com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:156)
at
org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
... 10 more
package helloWorld;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class java {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.facebook.com/");
System.out.println("LoginPage");
driver.quit();
}
}
You should set webdriver.chrome.driver property to point to the chromedriver.exe, not to chrome.exe
Download the relevant ChromeDriver package for your Chrome browser version
Unpack the archive somewhere
Amend the webdriver.chrome.driver property to point to the chromedriver.exe from step 2
That's it, you should be good to go now
Check out ChromeDriver - WebDriver for Chrome -> Getting Started for more detailed information if needed.
Until it's not too late be aware of Page Object design pattern, it is some form of Selenium scripting Best Practice which allows to split test logic from UI elements definitions making your tests easier to develop and especially maintain. Check out Design Patterns - Page Object Model for more detailed information and example test project.
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");
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();
The piece of code is:
another edit: would like to note that I'm using java to implement this so I don't think slashes would be a problem. (though correct me if i'm wrong)
edit: One more thing i'd like to add is that it actually says its starting up the chrome driver version something but immediately fails after that
System.setProperty("webdriver.chrome.driver", "webdrivers/chromedriver.exe");
driver = new ChromeDriver();
and the error i'll end up getting is
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.37.0', revision: 'a7c61cb', time: '2013-10-18 17:15:02'
System info: host: '****-PC', ip: '10.10.10.1', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_51'
There isn't a stack trace and this happens immediately after the webdriver attempts to start. I'm guessing the code above is where it happens simply because netbeans doens't really indicate where it errors out.
The mystery is that this worked on my computer but upon attempting to run it on a colleague's computer it simply produces this error. Firefox works for her but both IE and Chrome results in this. Any ideas?
edit: apparently there is a stack trace:
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)
... 7 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:8891/status] to be available after 20002 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
... 9 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)
... 10 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:201)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
... 11 more
You either need to add the absolute path which in Windows may need to include escaped backslashes e.g.
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
Or you can add the property to your System path.
If these options don't work it may be that there is a problem connecting to ChromeDriver. In which case you can open up the Chromedriver.exe file
WebDriver driver = new RemoteWebDriver("http://localhost:9515", DesiredCapabilities.chrome());
driver.get("http://www.google.com");
https://code.google.com/p/selenium/wiki/ChromeDriver
webdrivers/chromedriver.exe
I suspect it could not find chromedriver. Are you sure this is the right path to chromedriver.exe?
You should probably try with absolute path.
For example C:/Users/Name/Desktop/webdrivers/chromedriver.exe
Make sure that you are working with latest Chrome browser with one version behind and
The latest Chromedriver.exe version 2.9
The path should be mentioned like C://Test//chromedriver.exe
When I used the absolute path, it was giving me the error. However, when I used the directory where the executable was located, it started just fine. Here is a C# example
using OpenQA.Selenium.Chrome;
public class ChromeOptionsWithPrefs : ChromeOptions
{
public Dictionary<string, object> prefs { get; set; }
}
public static void Start()
{
var options = new ChromeOptionsWithPrefs();
options.AddArguement("-incognito");
using (IWebDriver driver = new ChromeDriver(#"C:\FilePath\", options))
{
//perform the test
driver.Navigate().GoToURL(#"http://www.google.com");
driver.Quit();
}
}
I just use the prefs to not store any data on whatever machine I am running the tests on. It is not needed, but you can pass some interesting options with it.