Reputation: 339
In Selenium Grid I am trying to execute a simple program and I'm getting Cannot find firefox binary in PATH
though I have added the binary path in my code.
My code and the error are given below.
Code
package Sample;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class sample1 {
WebDriver driver;
String BaseURL,NodeURL;
@BeforeTest
public void beforeTest() throws MalformedURLException {
BaseURL="www.google.com";
NodeURL="http://192.168.10.162:5566/wd/hub";
DesiredCapabilities capa =DesiredCapabilities.firefox();
capa.setBrowserName("firefox");
capa.setCapability("binary", "C:\\Users\\praveenraj.d\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
capa.setPlatform(Platform.ANY);
driver=new RemoteWebDriver(new URL(NodeURL),capa);
}
@Test
public void f() throws InterruptedException {
driver.get(BaseURL);
System.out.println(driver.getTitle());
Thread.sleep(50000);
}
@AfterTest
public void afterTest() {
driver.quit();
}
}
Error
[TestNG] Running:
C:\Users\praveenraj.d\AppData\Local\Temp\testng-eclipse-1233453386\testng-customsuite.xml
FAILED CONFIGURATION: @BeforeTest beforeTest
org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'IN-IF-WS1-0154', ip: '192.168.10.162', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_07'
Driver info: driver.version: FirefoxDriver
Command duration or timeout: 97 milliseconds
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_13'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
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.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)
at Sample.sample1.beforeTest(sample1.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'IN-IF-WS1-0154', ip: '192.168.10.162', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_07'
Driver info: driver.version: FirefoxDriver
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_13'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:72)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:59)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:55)
at org.openqa.selenium.firefox.FirefoxDriver.getBinary(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:107)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:62)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:56)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:216)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:170)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
SKIPPED CONFIGURATION: @AfterTest afterTest
SKIPPED: f
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@93b52b: 27 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@3ba002: 22 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@fa930d: 6 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@1f9c5c8: 6 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@197f158: 6 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 4 ms
Upvotes: 33
Views: 189196
Reputation: 81
Here are the steps to troubleshoot and fix this issue:
Cause: This error usually indicates that the tool/script could not find firefox on its default location
Troubleshooting Steps:
Step 1 - Check your firefox is installed on the default location
c:/Program Files (x86)/Mozilla Firefox
OR
C:\Program Files\Mozilla Firefox
Step 2 - Copy the path where your firefox.exe file is located
e.g. C:\Program Files\Mozilla Firefox\firefox.exe
Step 3 - Goto System Environment Variables, Select Path and click Edit
Step 4 - Add the location of firefox.exe file. Make sure not to change/delete existing values
Step 4 - Restart IDE
Step 5 - Save and Run the test again
Upvotes: 1
Reputation: 17553
Make sure that firefox must install on the default place like ->(c:/Program Files (x86)/mozilla firefox OR c:/Program Files/mozilla firefox, note: at the time of firefox installation do not change the path so let it installing in default path) If firefox is installed on some other place then selenium show those error.
If you have set your firefox in Systems(Windows) environment variable then either remove it or update it with new firefox version path.
If you want to use Firefox in any other place then use below code:-
As FirefoxProfile is depricated we need to use FirefoxOptions as below:
New Code:
File pathBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
DesiredCapabilities desired = DesiredCapabilities.firefox();
FirefoxOptions options = new FirefoxOptions();
desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
The full working code of above code is as below:
System.setProperty("webdriver.gecko.driver","D:\\Workspace\\demoproject\\src\\lib\\geckodriver.exe");
File pathBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
DesiredCapabilities desired = DesiredCapabilities.firefox();
FirefoxOptions options = new FirefoxOptions();
desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.co.in/");
Download geckodriver for firefox from below URL:
https://github.com/mozilla/geckodriver/releases
Old Code which will work for old selenium jars versions
File pathBinary = new File("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(firefoxBinary, firefoxProfile);
Upvotes: 21
Reputation: 1
Use older version of Firefox. 60.0.1 60.0.2 60.1.0 60.2.0 60.2.1 60.2.2 60.3.0 60.4.0 60.5.0 60.5.1 60.5.2 60.6.0 60.6.1 60.6.2 60.6.3 60.7.0 60.7.1 60.7.2 60.8.0 60.9.0
I have used 60.6.3 and issue resolved.
Upvotes: 0
Reputation: 1278
You can also use chromeWebDriver. latest version of it in download
code :
System.setProperty("webdriver.chrome.driver","yourplace\chromedriver.exe");
WebDriver driver = new ChromeDriver();
Upvotes: 0
Reputation: 1
Sometimes the solutions lie in simply uninstalling the application and installing it right back. Had a similar problem. Worked in my case. For some weird reason Firefox had not been installed in the default 'Programs' folder. Installed it again and issue got resolved.
Upvotes: 0
Reputation: 1
System.setProperty("webdriver.gecko.driver", "D:\\Katalon_Studio_Windows_64-5.10.1\\configuration\\resources\\drivers\\firefox_win64\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
DriverFactory.changeWebDriver(driver)
Upvotes: 0
Reputation: 1
I have also face same issue on Windows 10-64 bit OS.
When I am installed firefox on my PC its installed location is "C:\Program Files\Mozilla Firefox\firefox.exe" instead of "C:\Program Files (x86)\Mozilla Firefox", because OS is 64 bit,
So I just copy & paste "Mozilla Firefox" folder in "C:\Program Files (x86)" folder and execute selenium scripts, its work for me.
Upvotes: 0
Reputation: 81
java -jar selenium-server-standalone-2.53.1.jar -Dwebdriver.firefox.bin="C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
Put selenium jar file on desktop, go to cmd and run the above command.
Upvotes: 1
Reputation: 127
This issue may be because of the incompatibility of firefox driver and your firefox browser version. Download the latest version of firefox driver which is compatible with the updated Firefox browser version.
Upvotes: 1
Reputation: 2041
I didn't see the C# anwer to this question here. The trick is to set the BrowserExecutableLocation property on a FirefoxOptions instance, and pass that into the driver constructor:
var opt = new FirefoxOptions
{
BrowserExecutableLocation = @"c:\program files\mozilla firefox\firefox.exe"
};
var driver = new FirefoxDriver(opt);
Upvotes: 2
Reputation: 21
You need to add gecko driver
if you are using firefox v50
and above.
Use the following sample code :
File pathToBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
System.setProperty("webdriver.gecko.driver","C:\\Users\\Downloads\\selenium-java-3.0.1\\geckodriver.exe");
WebDriver driver = new FirefoxDriver(ffBinary,firefoxProfile);
Upvotes: 2
Reputation: 14105
Another option is to configure the server rather than the test client.
Configure the slave node service so that it knows where the firefox is. Install location can change from node to node, or even need multiple services running on a node to support access to different versions of FF.
java -jar "selenium-server-standalone-2.2.0.jar"
-Dwebdriver.firefox.bin="C:\FirefoxCollection\Mozilla Firefox 36.0\firefox.exe"
Upvotes: 22
Reputation: 21
I've just had this issue without changing PATH.
My PC is Win7, 64-bit system, If you are also using 64-bit system, you may want to try:
It must be under "Program Files (x86)" NOT "Program Files"
Hope it can help.
Upvotes: 2
Reputation: 348
I had the same issue in C# using 64-bit Windows and the 64-bit Firefox browser which doesn't seem to work on Selenium. If you are using the 64-bit browser, try the 32-bit one.
Surprisingly, the 32-bit Firefox browser runs on 64-bit Windows just fine.
Edited to clarify the intent of my post.
Upvotes: 5
Reputation: 1
This is due to RemoteWebDriver used in code, It tries to invoke firefox browser in node machine, If you have specified firefox binary location in "PATH" environment variable of node machine, It will open firefix browser on executing it from Hub.
Upvotes: 0
Reputation: 11323
Did you add firefox to your path after you have started the selenium server? If that is the case selenium will still use old path. The solution is to tear down & restart selenium so that it will use the updated Path environment variable.
To check if firefox is added in your path correctly you can just launch a command line terminal "cmd" and type "firefox" + ENTER there. If firefox starts then everything is alright and restarting selenium server should fix the problem.
Upvotes: 5
Reputation: 321
File pathToBinary = new File("C:\\user\\Programme\\FirefoxPortable\\App\\Firefox\\firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(ffBinary,firefoxProfile);
Upvotes: 32
Reputation: 2319
The easiest thing to do is have your grid nodes register the Firefox binary path as part of the node config. It uses the same capabilities that the client has, but allows you to pick the browser by name and let the node find it.
Please also note that the capability you want is "firefox_binary" and not "binary". You can see the full list of Firefox capabilities at this wiki page:
https://code.google.com/p/selenium/wiki/DesiredCapabilities
Upvotes: 1
Reputation: 3817
You should change environment variable and add there path to firefox.exe. The same could be done programmatically How can I set/update PATH variable from within java application on Windows?. I had the same problem on Win8.
Upvotes: 0