org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost error with IEDriverServer

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49528649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 10:22:56  来源:igfitidea点击:

org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost error with IEDriverServer

javaseleniumselenium-webdriverinternet-explorer-9selenium-iedriver

提问by srikanth

I have tried IE launch in webdriver as below, I have checked all protected mode settings in security tab of Internet Options, zoom level is 100%, environment variable even set, But not able to launch IE browser in the simple selenium code; Errors seen as Failed to connect to local host though gave url http://google.co.inand Caused by: java.net.ConnectException: Connection refused: Can someone please help me out with this issue. Thank you in advance

我试过如下在 webdriver 中启动 IE,我检查了 Internet 选项的安全选项卡中的所有保护模式设置,缩放级别为 100%,甚至设置了环境变量,但无法在简单的 selenium 代码中启动 IE 浏览器;被视为无法连接到本地主机的错误虽然给出了 url http://google.co.in并由以下原因引起:java.net.ConnectException:连接被拒绝:有人可以帮我解决这个问题。先感谢您

package eHMS_package;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class EHMS_Login {

    public WebDriver driver;

    public static void main(String[] args)
    {
        System.setProperty("webdriver.ie.driver", "E:/SRIKANTH/IEDriver/IEDriverServer.exe");
        WebDriver driver = new InternetExplorerDriver();
        driver.navigate().to("http://google.co.in");
    }
}

Error Details :

错误详情 :

Started InternetExplorerDriver server (64-bit)
3.9.0.0 Listening on port 48107 Only local connections are allowed Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:48107 Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:15.31Z' System info: host: 'UMANATH-PC', ip: '10.1.0.25', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161' Driver info: driver.version: InternetExplorerDriver    at 

org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
        at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:223)
        at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:215)
        at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:152)
        at eHMS_package.EHMS_Login.main(EHMS_Login.java:15)
    Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:48107
        at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:240)
        at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:158)
        at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)
        at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
        at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
        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:125)
        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:101)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:101)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
        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:125)
        at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:238)
        ... 28 more

采纳答案by DebanjanB

The error says it all :

错误说明了一切:

Started InternetExplorerDriver server (64-bit)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:48107 
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:15.31Z' 
System info: host: 'UMANATH-PC', ip: '10.1.0.25', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161' 
Driver info: driver.version: InternetExplorerDriver

It is clear from the error stack trace that InternetExplorerDriver serveris not getting detected back as in :

从错误堆栈跟踪中可以清楚地看出InternetExplorerDriver 服务器没有被检测到:

Driver info: driver.version: InternetExplorerDriver

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

您的主要问题是您使用的二进制文件之间的版本兼容性如下:

  • You are using Selenium Client v3.11.0
  • But you are using InternetExplorerDriverServer v3.9.0.0
  • 您正在使用Selenium Client v3.11.0
  • 但是你使用的是InternetExplorerDriverServer v3.9.0.0

So there is a clear mismatch between the Selenium Client v3.11.0and InternetExplorerDriverServer v3.9.0.0.

因此,Selenium Client v 3.11.0InternetExplorerDriverServer v 3.9.0.0之间存在明显的不匹配。

Solution

解决方案

  • Upgrade to InternetExplorerDriverServer v3.11.1.0
  • 升级到InternetExplorerDriverServer v 3.11.1.0