23

I am not able to run my script in any of the browsers. Below is the error i get for firefox. The location where firefox is installed is correct. Dont know what is wrong.

I am using Firefox 15. Selenium Java 2.2.0 and Eclipse Juno

My test case is given below:

import static org.junit.Assert.*;
import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver;  
import org.openqa.selenium.firefox.FirefoxProfile;

public class FirstTest {
private WebDriver _driver;
@Before
 public void setUp() throws Exception {
System.setProperty("webdriver.firefox.driver","C:\\Program Files\\Mozilla Firefox15\\Firefox.exe");
FirefoxProfile firefoxProfile = new FirefoxProfile();
_driver = new FirefoxDriver(firefoxProfile);
}

@Test 
public void Login() throws Exception {
_driver.get("https://www.google.co.in/");
assertEquals("Google", _driver.getTitle());
_driver.findElement(By.id("lst-ib")).clear();
_driver.findElement(By.id("lst-ib")).sendKeys("selenium");
_driver.findElement(By.name("btnG")).click();
_driver.findElement(By.linkText("Selenium - Web Browser Automation")).click();
assertEquals(" ", _driver.getTitle());
assertEquals("Selenium - Web Browser Automation", _driver.getTitle());
}
@After public void tearDown() throws Exception {
_driver.quit();
}
}

Below is the error i get:

org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA
Build info: version: '2.20.0', revision: '16008', time: '2012-02-27 19:03:59'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_26'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:52)
    at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:56)
    at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:52)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:88)
    at FirstTest.setUp(FirstTest.java:16)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

java.lang.NullPointerException
    at FirstTest.tearDown(FirstTest.java:31)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
kba
  • 19,333
  • 5
  • 62
  • 89
user2045704
  • 231
  • 1
  • 2
  • 3

15 Answers15

22
  1. Open Command line (Start -> Run -> type "cmd")
  2. type PATH
  3. Verify that you can see here written C:\Program Files\Mozilla Firefox15\Firefox.exe

It will be probably not here - because thats what the error says. How to fix it?

  1. Click Start
  2. Right click on "Computer" and click "Properties"
  3. In left menu Choose "Advanced system settings"
  4. Go to tab "Advanced" and click "Environment Variables..."
  5. In the window below select "Path" and click "Edit..." (Admin rights needed)
  6. Add at the end the desired path, semicolon separated
  7. Possible restart of computer needed

It his does not help then change the constructor like this:

File pathToBinary = new File("C:\\Program Files\\Mozilla Firefox15\\Firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
FirefoxDriver _driver = new FirefoxDriver(ffBinary,firefoxProfile);
Pavel Janicek
  • 14,128
  • 14
  • 53
  • 77
  • 1
    +1 I need to set the Firefox binary in Selenium because our work environment doesn't allow us to change PATH variable, so this one works well – vandershraaf Jul 22 '13 at 04:27
  • this issue was resolved and thanks, but i am getting one more issue after this and test failing with message: : org.openqa.selenium.logging.LocalLogs.getNullLogger()Lorg/openqa/selenium/logging/LocalLogs; -- can help me please. – Sun Jan 08 '14 at 05:52
  • kumar: It is always better idea to start new question. Describe here what you did and what have you tried. Else it will be lost in the comments... – Pavel Janicek Jan 09 '14 at 08:14
  • 8
    A computer reboot is not necessary, just an Eclipse restart will do (at least in my case). Also, the path should not include `firefox.exe` – Maria Ines Parnisari Jul 16 '14 at 05:21
  • This actually *launches* firefox for me. Is that what it is supposed to do? – Fuzzy Analysis Nov 11 '16 at 04:53
6

The simplest way is to use the below code before you define your Driver.

System.setProperty("webdriver.firefox.bin",
                    "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
Purus
  • 5,701
  • 9
  • 50
  • 89
6

be attention, if path to browser have space (as example "...\Program Files (x86)...") you need add double quotes to value of param.

Example:

-Dwebdriver.firefox.bin="D:\Program Files (x86)\Mozilla Firefox\firefox.exe"

All has been run successfully when added double quotes.

Kosmos
  • 333
  • 1
  • 5
  • 16
2

For some reason, adding the environment variable didn't work for me.

I was able to specify a path to Firefox in the command line node configuration, as described on this page (grid2).

-browser “browserName=firefox,version=3.6,firefox_binary=c:\Program Files\Mozilla Firefox\firefox.exe ,maxInstances=3, platform=WINDOWS”
DevDave
  • 6,700
  • 12
  • 65
  • 99
  • This worked for me. However, I had to remove the outer quotation marks and placed quotation marks around firefox_binary path value. – ansariwn Mar 05 '14 at 17:07
2

I was also suffering from the same issue. Finally I resolved it by setting binary value in capabilites as shown below. At run time it uses this value so it is must to set.

DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setCapability("platform", Platform.ANY);
capability.setCapability("binary", "/ms/dist/fsf/PROJ/firefox/16.0.0/bin/firefox"); //for linux

//capability.setCapability("binary", "C:\\Program Files\\Mozilla  Firefox\\msfirefox.exe"); //for windows                
WebDriver    currentDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);

And you are done!!! Happy coding :)

2

you have to add vm argument while running the program. This should be like

-Dwebdriver.firefox.bin=/custom/path/of/firefox/exe

In IntelliJ IDE much simpler Goto Run → Edit Configurations... In VM options add the above.

IntelliJ Run Configurations

Eclipse also have the options to give vm argument while running. This way I am using portable Firefox with selenium.

TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87
arulraj.net
  • 4,579
  • 3
  • 36
  • 37
  • I also use Firefox Portable and [this solution worked](http://stackoverflow.com/questions/20950748/cannot-find-firefox-binary-in-path-make-sure-firefox-is-installed/28955288#28955288). – Dan Dascalescu Aug 09 '15 at 13:30
1

GeckoDriver cannot find the installed Firefox. Firstly, make sure, you have matching GeckoDriver.exe to the Firefox version (32 bit vs. 64 bit) and ideally have them both up to date.

If the problem still persists, you can fix it in any of the following ways.

Most of the solutions have already been posted as answers to this and duplicated questions. I just wanted to summarize all of them and make them up-to-date.

  • Solution 1:

    Have your Firefox installed in default locations:

    • C:\Program Files\Mozilla Firefox\firefox.exe for 64bit Firefox and GeckoDriver_w64
    • C:\Program Files\Mozilla Firefox (x86)\firefox.exe for 32bit Firefox and GeckoDriver_w32
  • Solution 2:

    Add the folder with firefox.exe to the PATH environment variable.

    On Windows, open Control panel -> System -> Advanced system settings (on the outer left) -> Environment variables -> Path -> Add the folder which contains firefox.exe to PATH to:

    • (Current) User variables ... if you have Firefox installed only for that user (such as C:\Users\NAME\AppData\Mozilla Firefox).
    • (All user) System variables ... if Firefox is installed for all users (in C:\Program Files\Mozilla Firefox).

    You must restart your IDE and GeckoDriver.exe process for the changes to take effect.

    PATH environment variable

  • Solution 3:

    When you run Java Virtual Machine, you can add path to the firefox.exe as a system property (-D):

    java.exe   -Dwebdriver.firefox.bin="C:\Users\NAME\AppData\Mozilla Firefox\firefox.exe"   ...other_params...
    

    It is also possible to set up the VM parameters in IntelliJ IDEA, Eclipse, NetBeans etc. in their respective run configurations. IntelliJ IDEA run configuration

  • Solution 4:

    Globally inside your Java program (before you instantiate FirefoxDriver). Ideally as a first line of code inside your main() method.

    System.setProperty("webdriver.firefox.bin", "C:\Program Files\Mozilla Firefox\firefox.exe");
    
  • Solution 5:

    Inside your Java program, local to a single Firefox WebDriver instance:

    System.setProperty("webdriver.gecko.driver", "C:\\Java-Training\\Selenium\\geckodriver.exe");
    
    FirefoxOptions options = new FirefoxOptions();
    File pathToFirefoxBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
    FirefoxBinary ffBinary = new FirefoxBinary(pathToFirefoxBinary);
    options.setBinary(ffBinary);
    
    browser = new FirefoxDriver(options);
    
Shine Developer
  • 186
  • 1
  • 7
0

I was also facing the same problem and I spent more than a week to fix it. Restarting my machine seemed to have fixed it, but only temporarily.

There was a solution to increase the maximum number of ephemeral ports by editing the registry file. That seemed to have fixed the problem but that also, only temporarily.

For sometime, I kept thinking if I was trying to access a driver which is no longer available, so I have tried to call:

driver.quit()

And then recreate the browser instance, which only gave me: SessionNotFoundException.

I now realized that I had used BOTH System.setProperty as well as ffCapability.setCapability to set the path of the binary.

I then tried with only System.setProperty => No luck there.

Only ffCapability.setCapability => Voila!!! So far it has been working fine. Hopefully it will work great when I try to re-run my scripts tomorrow and the day after and the day after... :)

Bottomline: Use only this

ffCapability.setCapability("binary", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //for windows`

Hope it helps!

Gustavo Morales
  • 2,614
  • 9
  • 29
  • 37
user6376
  • 3
  • 1
  • 4
0

For me it was just a matter of changing the path variable to: 'C:\Program Files\Mozilla Firefox' instead of 'C:\Program Files (x86)\Mozilla Firefox'

Eyal Sooliman
  • 1,876
  • 23
  • 29
0

I got this error message while running tests in Visual Studio: Firefox simply wouldn't load and I got OP's error message.

I manually opened Firefox and found out that it needed to update itself (it did so before loading). Once finished I reran the test suite and Firefox showed up nicely, the tests were properly ran. If you get this error all of a sudden please try this answer before updating anything on your machine.

Justa
  • 1
0

This code simply worked for me

System.setProperty("webdriver.firefox.bin", "C:\\Program Files\\Mozilla Firefox 54\\firefox.exe");
String Firefoxdriverpath = "C:\\Users\\Hp\\Downloads\\geckodriver-v0.18.0-win64\\geckodriver.exe";
System.setProperty("webdriver.gecko.driver", Firefoxdriverpath);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
jq170727
  • 13,159
  • 3
  • 46
  • 56
0

I had this problem when moving my project from one computer to another. The solution was to reload selenium webdriver from nuget.

user890332
  • 1,315
  • 15
  • 15
0

Try this:

System.setProperty("webdriver.gecko.driver", "geckodriver p");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
Robert Columbia
  • 6,313
  • 15
  • 32
  • 40
Daniel
  • 1
  • 6
    Please not just post a code block, edit your answer and give some detail how this code block solves the problem. – juzraai Jun 28 '18 at 18:30
0
File pathBinary = new File("Firefox.exe location");
FirefoxBinary ffBinary = new FirefoxBinary(pathBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
FirefoxDriver driver = new FirefoxDriver(ffBinary,firefoxProfile);

You need to add binary of the browser

or

Best and forever solution: Just add Firefox.exe location to environmental variables

dheeraj reddy
  • 1,019
  • 2
  • 13
  • 24
0

It seems that Firefox gets installed in the App data folder Path C:\Users\users\AppData\Local\Mozilla Firefox

So you can set the firefox bin property as below

System.setProperty("webdriver.firefox.bin", "C:\\Users\\*USERNAME*\\AppData\\Local\\Mozilla Firefox\\Firefox.exe");

Adding this resolved the issue for me

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73