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/
Related
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 trying to upload file to Safari(8.0.8) using webdriver. Can anyone confirm it is possible or not? I was searching this problem and I cant find clear information.
My test environment:
I run test at my local PC with Win7 and browser start at Selenium Grid which is running on MAC machine (hub + node run at MAC Yosemite 10.10.5)
First, I try to upload direct file on MAC. But it is not working.
Browser.Driver.FindElement(By.Id("inputID")).SendKeys("/Users/administrator/Desktop/file.txt");
Next, I try to use LocalFileDetetor but it also doesn't work:
driver.FileDetector = new LocalFileDetector();
Browser.Driver.FindElement(By.Id("inputID")).SendKeys("c:\\file.txt");
Next, I try to use: WebDriverBackedSelenium:
ISelenium safari = new WebDriverBackedSelenium(webDriver, "http://systemname/");
safari.Start();
safari.AttachFile("xpath=//input[#id='inputID']", "e:\\file2.txt");
But it doesn't work too. Stack trace:
Selenium.SeleniumException : WebDriver exception thrown
----> OpenQA.Selenium.InvalidElementStateException : Element must be user-editable in order to clear it. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'mac.domain.company.com', ip: '192.168.136.67', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_51'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{browserName=safari, takesScreenshot=true, javascriptEnabled=true, version=8.0.8, cssSelectorsEnabled=true, platform=MAC, secureSsl=true}]
Session ID: null
It doesn't work because it is Safari or there is problem with grid/safari/remote host or with file path(something with / )?
Looks like it is not supported https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4220
You can upload using OSAScript. Please do the following:
Create .scpt file in mac with below code
activate application "Safari"
tell application "Safari"
tell document 1
do JavaScript "document.getElementsByTagName('label')[0].click()"
delay 2
end tell
end tell
tell application "System Events"
keystroke "G" using {command down, shift down}
delay 2
keystroke "/Users/melamc/Downloads/upload.jpeg"
delay 2
keystroke return
delay 2
keystroke return
delay 2
end tell
trigger this file whenever you required (write a code to run this file programetically
I hope this will help you, try and let me know
I have done a lot of research to accomplish the uploading of file in safari browser on mac and fortunately I came up with the below solution.
Following are the possible prerequisites to match the given solution:
Programming Environment: c#
Automation Environment: Selenium WebDriver, Selenium Grid
Browser: Safari (12)
OS: MAC (High Sierra)
Hub: Windows machine, Node: Mac machine
In the context of the above to upload the file one can implement the following lines of code.
DesiredCapabilities dc = new DesiredCapabilities();
dc.SetCapability(CapabilityType.BrowserName, "safari");
dc.SetCapability(CapabilityType.Version, "12");
Driver = new RemoteWebDriver(new Uri("http://Node_Ip_Address:Port/wd/hub/"), dc);
Below lines of code do the magic, (This also works for Chrome, and Firefox.)
IAllowsFileDetection AllowsDetection = Driver as IAllowsFileDetection;
if (AllowsDetection != null)
{
AllowsDetection.FileDetector = new LocalFileDetector();
}
In java, the equivalent of the above is
Driver.setFileDetector(new LocalFileDetector());
Reference: https://saucelabs.com/blog/selenium-tips-uploading-files-in-remote-webdriver
The code line written for java has not been tested from my end as I am currently working in c#.
Happy Testing.
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.
I have this problem. When on different computer, I start HUB and NODE and then run my tests where I initialize Google Chrome like this:
Selenium selenium = new DefaultSelenium("localhost", 4444, *googlechrome, "http://www.google.com");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Everything runs ok on my computer - Chrome comes up and does the script. However, If my friend tries to do exactly the same, she gets this error:
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: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_29'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:435)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:139)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:94)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:102)
at com.deutscheboerse.test.PerfTests.<init>(PerfTests.java:52)
at com.deutscheboerse.test.EUAStressTest.myTest(EUAStressTest.java:37)
at com.deutscheboerse.test.EUAStressTest.main(EUAStressTest.java:60)
Caused by: org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 4422; received: 3743
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:197)
at org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:105)
at org.apache.http.conn.BasicManagedEntity.streamClosed(BasicManagedEntity.java:152)
at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:237)
at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:186)
at org.apache.http.util.EntityUtils.consume(EntityUtils.java:67)
at org.openqa.selenium.remote.HttpCommandExecutor$EntityWithEncoding.<init> HttpCommandExecutor.java:399)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:287)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:415)
... 6 more
So far only difference what I found is, that hers hub is listening on http://10.10.190.134:5555 mine is listening on http://10.131.7.44:5555 but both can access the console on same IP and port. I dont have any clue whats wrong. Everything is appreciated, thanks
** EDIT **
Iried to run it on another computer and I had the same error. Little debugging showed me this message:
11:04:01.899 WARN - Exception: The path to the chromedriver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list
So, prior setting up the Chrome in Selenium Grid, I need to do this:
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver.exe");
I tried to do it and stil unable to run the Chrome... Any help is still wanted
EDID2
This is how I exactly set the property:
File file = new File("lib/chromedriver.exe");
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, file.getAbsolutePath());
I am using this approach because I need to run it on more computer and the JAR file can have different locations.
BTW, the warning is found in window with Selenium Grid in role node. I am thinking, if there is any other switcher. So far I am running these commands:
java -jar lib//selenium-server-standalone-2.20.0.jar -role hub
java -jar lib/selenium-server-standalone-2.20.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 12
and then my JAR. The exception is in window with the NODE. Is there any switcher?
After a day searching, I have working solution. Everything is in how do you start the node. So first, do the usual:
java -jar lib/selenium-server-standalone-2.20.0.jar -role hub
Then start the node like this:
java -jar lib/selenium-server-standalone-2.20.0.jar -role webdriver -hub http://localhost:4444/grid/register -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=5 -Dwebdriver.chrome.driver=lib\chromedriver.exe
More specifically: You have to start up the NODE with parameter browser and add -D parameter specifying the full path to the ChromeDriver
My huge thanks goes to John Naegle who answered similar question here on SO regarding the Internet Explorer - see here
That's funny, but webdriver cannot resolve dns, http://localhost:4444/
I edited my host file, uncommented line:
127.0.0.1 localhost
And It's done.
I am trying to run my test cases on Chrome and I had copied the path in the Properties file,but still console is throwing annoying statements like:
ERROR: The path to the chromedriver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromium/downloads/list
FAILED CONFIGURATION: #BeforeTest startWebSession
java.lang.NullPointerException
One thing I have found is that the Chrome driver cannot be started from within Eclipse. It must be run from a command prompt. At least on Windows 7 64-bit.
Trying to run it from within Eclipse produces this exception:
Exception in thread "main" java.lang.IllegalStateException: The webdriver.chrome.driver system property defined chromedriver executable does not exist: C:\Windows\System32\chromedriver.exe
This problem only occurs for Chrome. IE and FireFox work fine from within Eclipse.
Download the chrome driver from http://code.google.com/p/chromedriver/downloads/list
Initialize your driver object in the following manner -
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
By doing this the chrome driver works properly.
This is how do I initialize the ChromeDriver:
public RegulationUI() throws Exception{
ChromeDriverService service = ChromeDriverService.createDefaultService();
File file = new File(RegulationUI.class.getResource("/chromedriver.exe").toURI());
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver(service,options);
}
BTW my test class is named RegulationUI
Try this, it works for me and moreover, I know that this is "multicomputer" solution - our project is in subversion and this way everybody can run it, even if we have differently setup where exactly on disk the "working folder" for IDE is
Please download chromedriver.exe for Google chrome browser
please download IEdriver.exe for Internet explore.
Please And kept these files in a root folder of windows for simplicity. Lets consider your operating systems installed on c:\ (C Driver) create a folder name Selenium on C-Drive and Kept these binary(.exe) files. like c:\selenium
in your Testcase/testScript Write as
//For Chrome Browser:
Webdriver driver = new ChromeDriver();
java.io.File file = new File("c:\\selenium\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
If you are using maven then try to use following in your pom:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>RELEASE</version>
</dependency>
and use it like this for chrome in your setup:
ChromeDriverManager.getInstance().setup();
driver = new ChromeDriver();