pooja patil
pooja patil

Reputation: 11

org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0 using GeckoDriver Firefox and Selenium

import org.openqa.selenium.firefox.FirefoxDriver;

public class OpenBrowser {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.gecko.driver", "C:\\StudyPooja\\geckodriver.exe");
        System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "C:\\StudyPooja\\Mylog.txt");
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.facebook.com/");
        Thread.sleep(5000);
    }
}

The Error I'm getting is:

Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:14170 Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:05:20.749Z' System info: host: 'D790-18', ip: '192.168.43.66', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31' Driver info: driver.version: FirefoxDriver at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:130) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:125) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:103) at OpenBrowser.main(OpenBrowser.java:13) Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:14170 at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:242) at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:160)

Upvotes: 1

Views: 2531

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193298

This error message...

Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:14170 
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:05:20.749Z' 
System info: host: 'D790-18', ip: '192.168.43.66', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31' 
Driver info: driver.version: FirefoxDriver at

...implies that the GeckoDriver was unable to initiate/spawn a new Browsing Context i.e. Firefox Browser session.

Your main issue is the incompatibility between the version of the binaries you are using as follows:

  • Your Selenium Client version is 3.14.0 of 2018-08-02T20:05:20.749Z which is more than a year older.
  • Your JDK version is 1.8.0_31 which is pretty ancient.
  • Your GeckoDriver version is unknown to us.
  • Your Firefox version is unknown to us.

So there is a clear mismatch between the JDK v8u31 , Selenium Client v3.14.0.


Solution

  • Upgrade JDK to recent levels JDK 8u222.
  • Upgrade Selenium to current levels Version 3.141.59.
  • Upgrade GeckoDriver to GeckoDriver v0.26.0 level.
  • GeckoDriver is present in the desired location.
  • GeckoDriver is having executable permission for non-root users.
  • Upgrade Firefox version to Firefox v70.0 levels.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your Test as a non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

Upvotes: 0

Related Questions