Jrawr Jrawr - 20 days ago 9
Java Question

Selenium FireFoxDriver unable to connect

I've been attempting to use Selenium to drive Firefox for the fist time. I used virtually identical code to drive Chrome without issue. However, when I attempt to use the Firefox driver, the browser opens, stalls, and then, after about 60 seconds, I get an error report that reads as follows:

Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
4474-a285-3208198ce6fd}","syncGUID":"dcskEFBTLyBH","location":"app-global","version":"48.0.1","type":"theme","internalName":"classic/1.0","updateURL":null,"updateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"icons":{"32":"icon.png","48":"icon.png"},"iconURL":null,"icon64URL":null,"defaultLocale":{"name":"Default","description":"The default theme.","creator":"Mozilla","homepageURL":null,"contributors":["Mozilla Contributors"]},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"descriptor":"C:\\Program Files\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","installDate":1471881400240,"updateDate":1471881400240,"applyBackgroundUpdates":1,"skinnable":true,"size":21905,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"hasBinaryComponents":false,"strictCompatibility":true,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"48.0.1","maxVersion":"48.0.1"}],"targetPlatforms":[],"seen":true}
1472056603181 addons.xpi DEBUG getModTime: Recursive scan of {972ce4c6-7e08-4474-a285-3208198ce6fd}


I've checked other guides and all they recommend is that I update my .jar files. I am using selenium-java-3.0.0-beta2 and Firefox 48.0.1 to test so my files are up to date. I would like to get this to run properly.

UPDATE: code still does not work and I've set the System property to set the geckodriver properly. However, I still cannot get the driver to function properly. It won't even launch the browser any more.

import org.openqa.selenium.*;


import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class SimpleFireFoxDriver {

public static void main(String[] args) {

System.setProperty("webdriver.gecko.driver","C:\\Selenium\\geckodriver.exe");

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);

WebDriver driver = new FirefoxDriver();

driver.get("http://www.youtube.com");

System.out.println("Made it to the promised land");

driver.quit();

}

}


Edit: Also the path to FireFox itself is located here:
"C:\Program Files\Mozilla Firefox\firefox.exe"

Answer

This is happening because you have set the wrong system property. You need to set system property as follows:

System.setProperty("webdriver.gecko.driver","C:\\Selenium\\geckodriver.exe");

Selenium firefox driver expects this System property to be set before initiating marionette driver and launching firefox. And if you don't set any System property and try to instantiate Firefox driver then you will get following error : "The path to the driver executable must be set by the webdriver.gecko.driver system property."

Hope this helps.