Pergunta

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.

Foi útil?

Solução

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!

Outras dicas

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/

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top