WebDriverException was encountered while attempting to establish a connection with localhost/0:0:0:0:0:0:0:1:1941 using GeckoDriver and Selenium due to a java.net.ConnectException

I am currently facing an issue while trying to set up Eclipse for writing a basic automated test. Specifically, I am encountering difficulties in launching Firefox. Below is the code I have written along with the error stack that follows:

Here's the code snippet:

package cucumberTest;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class seleniumTest {

    private static WebDriver driver = null;

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        //https://www.toolsqa.com/cucumber/first-cucumber-selenium-java-test/
        // new instance of frefox driver
        driver = new FirefoxDriver();

         //Put a Implicit wait, this means that any search for elements on the page 
         // could take the time the implicit wait is set for before throwing exception

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        //open page
         driver.get("http://www.store.demoqa.com");

The following is the Error Stack displayed in the console window when attempting to run the code in ECLIPSE:

Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:1941
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'LAPTOP-P3SB6R8A', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
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:552)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
    at cucumberTest.seleniumTest.main(seleniumTest.java:18)
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:1941
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:247)
    at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:165)
    at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
    at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
    at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
    at okhttp3.RealCall.execute(RealCall.java:77)
    at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:105)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    ... 6 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at okhttp3.internal.platform.Platform.connectSocket(Platform.java:129)
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:245)
    ... 28 more

I would greatly appreciate any assistance in identifying and resolving this problem. Thank you!

Answer №1

This particular 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:1941
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'LAPTOP-P3SB6R8A', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: FirefoxDriver
.
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:1941

This indicates that the program failed to initialize a new GeckoDriver service.

If you are using Selenium v3.x, GeckoDriver and Firefox to start a new GeckoDriver service and Firefox Browser session, make sure to provide the correct Key webdriver.gecko.driver paired with the Value set as the absolute path of the GeckoDriver using the System.setProperty() method like this:

System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
driver = new FirefoxDriver();

In addition,

  • Your JDK version is 1.8.0_161 which might be outdated.
  • The version of your Selenium Client is v3.141.59.
  • We do not have information about the versions of your GeckoDriver and Firefox.

Hence, there seems to be a mismatch between JDK v8u161 and Selenium Client v3.141.59.

Solution

  • Upgrade your JDK to the latest version such as JDK 8u202.
  • Update your GeckoDriver to GeckoDriver v0.24.0.
  • Make sure that GeckoDriver is available at the specified location.
  • Ensure that GeckoDriver has executable permission for non-root users.
  • Upgrade your Firefox to version Firefox v65.0.
  • Clean your Project Workspace in your IDE and rebuild the project with necessary dependencies only.
  • If your base Web Client version is too outdated, uninstall it using Revo Uninstaller and install a more recent version.
  • Reboot the system.
  • Execute your Test as a non-root user.
  • Always remember to include driver.quit() within the tearDown(){} method to close and destroy the instances of WebDriver and Web Client properly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Selenium technique for navigating iframes without specific identifiers

I encountered an issue while trying to switch to an iframe on a page I am scraping. The ID has been removed from the iframe, making it difficult for me to switch to it. Unfortunately, I have not been able to find any helpful documentation on this matter. I ...

A combination of Tor Browser, Selenium, and Javascript for

I have been attempting to use selenium with Tor, but unfortunately it is not functioning correctly. I have come across a library that allows for this functionality, however, it appears to only work with Python. Is there a way to accomplish this using Jav ...

Issue with Google Calendar: Unable to locate com.google.api.client.json.JsonFactory.fromInputStream

Currently, I'm developing a Spring-MVC application and I'm facing an issue while trying to integrate Calendar functionality. The problem seems to be related to authentication due to a json error. I have been using Googles sample code but it appea ...

When the Protractor configuration is executed, it displays the message "The requested webpage cannot be accessed."

Testing protractor on a vanilla.js app and encountering an error when running protractor basicConf.js The following error is occurring: This webpage is not available ERR_CONNECTION_REFUSED Here is the test script in use: describe('foo', fun ...

The titles and view counts of YouTube videos are not displayed

I am currently working on a project to extract and print the title and view count of each video from different YouTube channels listed in my urls. I encountered an issue where it only displayed results for one channel (https://www.youtube.com/c/TuckerBud ...

Parsing JSON data in Java may require skipping over certain characters before successfully parsing the data

Currently, my focus is on handling json responses and processing them with a json parser. However, there are some cases where the json response includes a specific format like 'jquery-id99999999({json response})'. When this format is encountere ...

Unable to select the element

I'm currently working on automating the process of browsing through multiple pages of doctor listings. My main challenge lies in getting selenium to locate and click on the right arrow that navigates to the subsequent pages containing 10 doctors each. ...

An error occurred in the devtools session due to a WebException, stating that the remote name could not be resolved for 'http'

After setting up a new session to Support DevTools Session on docker for selenium 4, I encountered an issue. Everything seems to be working as expected during debugging until I reach the devtools session, where I encounter the error "WebException: The re ...

Encountering an issue with WebDriver in the realm of JavaScript

I am struggling to use JavaScript to locate specific controls and send values to them. One example is changing the text in a textbox with the ID "ID" to "123456". Below is the code I tried: ((IJavaScriptExecutor)driver).ExecuteScript("document.getElement ...

The Selenium bot designed for leaving comments on YouTube videos is having trouble locating the comment box on the

Seeking assistance urgently. Provided below is the complete code snippet for logging into YouTube using Selenium's .find_element methods. I am struggling to navigate to specific videos, scroll down, and select a YouTube comment box. Despite trying v ...

Tips for extracting real-time data from a map using JavaScript scraper

As a new Python user, I am looking to scrape data from the following website: The challenge I'm facing is that the data on the website is dynamically generated. I have tried different solutions but none of them seem to work. With Selenium, I usually ...

converting webdriver code into integers

I am attempting to extract variables 'a' and 'b' from this HTML code. Currently, I am working on creating an automation script using Python and Selenium. The task involves a math game website where users perform addition, subtraction, ...

Generating emails for failed test cases in Selenium WebDriver can serve as a useful tool for quality assurance teams

Having trouble sending email notifications for failed test cases in Selenium WebDriver? Currently, you are able to send generic emails for both passed and failed test cases at the end of the test suite using TestNG framework. However, the specific requirem ...

What is the best way to locate common data between two lists?

My current situation involves working with two lists that contain web elements. List<WebElement> assert_number= driver.findElements(By.xpath("//div[@class='tabs__body-inner']")) ; assert_number: This list includes multiple brand ...

Ensure you are patient and vigilant for the alert pop-up to show up on the webpage following a click action,

Upon initiating a search on the webpage, an alert popup will be displayed. I must find a way to wait for the popup to appear without relying on Thread.sleep. ...

How to automatically accept alerts in Selenium using the IE driver

When faced with this scenario: there is a list displayed on the page accompanied by a checkbox to select all items in the list, and a div container to contain the selected items, upon clicking, an alert pops up, and upon accepting the alert, the page close ...

What methods can programming languages use to direct the Lua (or Python) interpreter to run commands specified by the program?

I am currently running on an operating system called Cent OS 7. I have a desire to develop a program, which may be written in Java or another language, that can communicate with the Lua interpreter. It is my goal for this program to send commands to the L ...

Using Selenium to extract data from a table in Python

I am currently exploring web scraping techniques using Python's Selenium library. My goal is to extract data from a table on a website using Selenium. Since I am still learning Python and Selenium, please bear with me if my code seems amateurish. f ...

Guide on incorporating curl in Java and extracting JSON feedback

Is it possible to use a curl command that provides a JSON response in Java and parse the JSON response using Java? Here is an example of Java code attempting to achieve this: public static void main(String[] args) throws Throwable { try { In ...

Encountering an issue while performing Python Selenium testing on the login and logout features

Encountering an error message... Error: AttributeError: 'LoginTestCase' object has no attribute 'driver' Here is the code snippet: from selenium import webdriver; from selenium.webdriver.common.keys import Keys import time import unit ...