java.net.ConnectException: Failed to connect to localhost error with Selenium 3.11.0 with IEDriverServer and IE 11 on Windows 10

Divakar Ragupathy picture Divakar Ragupathy · Mar 14, 2018 · Viewed 14.4k times · Source

I am very new to selenium and trying to set up selenium in my laptop to begin. I am unable to invoke IE from my simple code. The details are given below. Can you please help me to understand where the issue is

IE version: IE 11, IE Driver: 64-bit, OS: Windows 10 64 bit, Selenium version: 3.11

Error:

Code:

mport java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

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

		  WebDriver web;
		  /*System.setProperty("webdriver.chrome.driver","C:\\Users\\Divakar\\Documents\\General\\Learnings\\Selenium\\Others\\Set Up files\\Browser Drivers\\" + "chromedriver_x32.exe");
		  ChromeOptions chromeOptions = new ChromeOptions();
			chromeOptions.setExperimentalOption("excludeSwitches",Arrays.asList("test-type"));
			web = new ChromeDriver(chromeOptions);
			web.manage().window().maximize();
			web.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);*/
			
		  System.setProperty("webdriver.ie.driver","E:\\General\\Learnings\\Selenium\\Others\\Set Up files\\Browser Drivers\\" + "IEDriverServer.exe");
			DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
	        capab.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
	        web = new InternetExplorerDriver();
	        web.manage().window().maximize();
	        web.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);

		    /*FirefoxDriver web = new FirefoxDriver();			
	        web = new FirefoxDriver();	
	        web.manage().window().maximize();
	        web.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);*/
	        
		web.get("http://www.icicibank.com/");
		web.findElement(By.xpath("/html/body/div[1]/div[1]/div[1]/div/a[1]")).click();
		web.findElement(By.xpath("/html/body/div[1]/div[1]/div[1]/div/div[3]/div/ul[1]/li[1]/a")).click();
	    web.findElement(By.xpath("/html/body/div[1]/div[2]/div[2]/div/div[1]/div/div[3]/a")).click();
	    web.findElement(By.name("AuthenticationFG.USER_PRINCIPAL")).sendKeys("507133118");
	    web.findElement(By.name("AuthenticationFG.ACCESS_CODE")).sendKeys("Soft2008");
	    web.findElement(By.name("Action.VALIDATE_CREDENTIALS")).click();
	    web.findElement(By.id("ContentLink1")).click();
	    

	    WebElement accttable =  web.findElement(By.xpath("/html/body/form/div/div[3]/div[1]/div[4]/div[2]/div/div/div[5]/div/div/div/div/div/div/div"));
		List<WebElement> all_rows =  accttable.findElements(By.tagName("tr"));
	    
		int j = 0;
		for (int i = 0; i < all_rows.size(); i++) {
	    	List<WebElement> rowAllCells = all_rows.get(i).findElements(By.tagName("td"));			
			if(rowAllCells.size()>1)
			{

				String acctno=rowAllCells.get(2).getText();
				if(rowAllCells.get(2).getText().trim().equalsIgnoreCase("602605049934"))
				{
					web.findElement(By.id("AccountSummaryFG.SELECTED_INDEX")).click(); ///html/body/form/div/div[3]/div[1]/div[4]/div[2]/div/div/div[5]/div/div/div/div/div/div/div/table/tbody/tr[4]/td[1]/input
					web.findElement(By.id("HREF_actNicNameOutput[" + j + "]")).click();
					web.findElement(By.id("backBtn")).click();
					web.findElement(By.id("VIEW_MINI_STATEMENT")).click();
					web.findElement(By.id("HREF_Logout")).click();
					web.close();
				}
				else 				j = j + 1;
			}
		}
	    
	    		
	    
	  }
	}

Answer

DebanjanB picture DebanjanB · Mar 15, 2018

The error says it all :

3.9.0.0
Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:29313
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'DESKTOP-B1D1PSJ', ip: '192.168.79.96', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: InternetExplorerDriver

It is clear from your error stack trace that the new session is not getting initiated and the driver.version is also not getting recognized.

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

  • You are using Selenium Client v3.11.0
  • You are using IEDriverServer v3.9.0.0
  • You are using InternetExplorer v11.0 (as per your question)

So there is a clear mismatch between the Selenium Client v3.11.0 , IEDriverServer v3.9.0.0.

Solution

  • Upgrade IEDriverServer to v3.11.1.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
  • If your base Web Browser base version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Browser.
  • Execute your @Test.

Additional Considerations

  • You are using the flag INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true which is against the best practice. Don't do it.