org.openqa.selenium.WebDriverException: java.net.ConnectException: 无法使用 IEDriverServer 连接到本地主机错误

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

我试过在 webdriver 中启动 IE,如下所示,我已经检查了 Internet 选项的安全选项卡中的所有保护模式设置,缩放级别为 100%,甚至设置了环境变量,但无法在简单的情况下启动 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");
    }
}

错误详细信息:

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

错误说明了一切:

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

从错误堆栈跟踪中可以清楚地看出,InternetExplorerDriver 服务器 没有像在 :

中那样被检测到
Driver info: driver.version: InternetExplorerDriver

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

  • 您正在使用 Selenium Client v3.11.0
  • 但是您正在使用 InternetExplorerDriverServer v3.9.0.0

所以 Selenium 客户端 v3.11.0InternetExplorerDriverServer v[=27 之间存在明显的不匹配=]3.9.0.0.

解决方案

  • 升级到 InternetExplorerDriverServer v3.11.1.0