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.
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 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.
Unable to find/open Firefox Binary - webdriver/robot framework
My tests run fine in java and fitnesse. They also run fine when executing them through robot framework with Internet Explorer and Chrome. However when I execute them through Firefox, using 'new FirefoxDriver()', I receive the following error:
DEBUG java.lang.ExceptionInInitializerError
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java: 81)
Caused by: java.lang.NullPointerException
org.openqa.selenium.firefox.FirefoxBinary.<clinit>(FirefoxBinary.java: 42)
... 183 more
In the FirefoxBinary and FirefoxDriver classes these lines correspond to the following code:
FirefoxBinary ln42-43
private static final String PATH_PREFIX = "/" +
FirefoxBinary.class.getPackage().getName().replace(".", "/") + "/";
and FirefoxDriver ln 80-82
public FirefoxDriver(FirefoxProfile profile) {
this(new FirefoxBinary(), profile);
}
I have tried setting the path to the Firefox binary in my classpath, pythonpath (used by robotframework) and path. I have also written the following lines of code to try to force the binary to be found:
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(FirefoxDriver.BINARY, "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
I have tried to execute the tests on two computers, my work and home machines. Further I have tried to use a firefox profile created using firefox.exe –p and also by creating one in the java code. I have tried Firefox 6-8. Unfortunately none of these things have worked.
I am also using/have used:
Java 1.6
Selenium 2.9.0/2.13.0
Windows 7
I am unsure if this is related but as a work around I have been trying to get Firefox to run through a remote browser. I have been trying the following code:
rcc = new RemoteControlConfiguration();
rcc.setPort(4447);
rcc.setPortDriversShouldContact(4447);
rcc.setInteractive(true);
rcc.setSingleWindow(true);
rcc.setTimeoutInSeconds(30);
ss = new SeleniumServer(rcc);
ss.start();
DesiredCapabilities cap = new DesiredCapabilities();
cap.setJavascriptEnabled(true);
cap.setBrowserName("firefox");
URL url = new URL ("http://www.google.com/");
driver = new RemoteWebDriver(url,cap);
However when I run the above I get the following error message:
Exception in thread "main" org.openqa.selenium.WebDriverException: Error communicating with the remote browser. It may have died.
Build info: version: '2.13.0', revision: '14794', time: '2011-11-18 17:49:47'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0'
Driver info: driver.version: Selenium2Driver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:412)
Does anyone have any idea on how to fix either of my problems?
Any help would be greatly appreciated, I feel very stuck on this issue atm. Two days of trying to get Firefox to work when Internet Explorer already does….. It feels as if the world is about to end.
Thanks,
James
EDIT:1
It is possible for me to run Firefox by using selenium-server.
James, FYI, URL for RemoteWebDriver appears incorrect in post above. Should be something more like "localhost:4444/wd/hub";? Interestingly, I'm having the opposite problem with Web Driver, having issues starting Firefox via RemoteWebDriver but Firefox runs fine via native FirefoxDriver. IE works fine over remote. – David Dec 4 '11 at 4:51
Thanks David!
I am not understanding why you have not configured your Firefox binary in your remote grids config.json file? That's how I would do it. Then, your DesiredCapabilities object would not need to define it. A hint can be found here.
If it works, the line in the JSON file might look like:
"binary": "C:/Program Files/Mozilla Firefox/firefox.exe",
I guess it doesn't allow you to dynamically set the binary location from your code, but perhaps you can try it that way to prove if it should work or not as a troubleshooting step.
FirefoxProfile profile = new FirefoxProfile();
FirefoxBinary binary = new FirefoxBinary(new File("C:\\path to firefox\\firefox.exe"));
driver = new FirefoxDriver(binary, profile);
try this
This kind of issue obtained because of selenium web driver fail to find the .exe files of Firefox. Please check whether C:\Program Files (x86)\Mozilla Firefox you have exe file in the location and don’t forget to set environment variable having the java jdk path.
Source:- read [Solved Cannot find firefox binary in PATH Selenium][1]http://www.tech4crack.com/solved-cannot-find-firefox-binary-in-path/