Eclipse Java Selenium无法连接到localhost

时间:2018-05-05 23:02:43

标签: java selenium-webdriver

首先,我是java的绝对初学者(因此也是eclipse),也是selenium。

我需要与我的java程序的任何浏览器进行交互(获得像textfield这样的objekt并填充字符串)。该程序最终应该做的只是将信息从更加精简的String数组传递到浏览器中的互联网页面(所以没有什么全新的)。 到目前为止。 java中的这种交互似乎只能通过我最近下载的selenium来实现。显然也需要geckodriver。

这是我尝试启动浏览器的代码。 (我尝试了几种不同的浏览器)。

以下是我发现的一些解决方案但没有带来任何改进。 - 更新版本。 - 指定字符串(这就是它当前的样子:String service =“D://IEDriverServer.exe”;)

import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.grid.selenium.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;


public class firefoxöffner {


        public static void main(String[] args) throws IOException, URISyntaxException {


            String service = "D://IEDriverServer.exe";
            System.setProperty("webdriver.ie.driver", service);
            InternetExplorerDriver  driver = new InternetExplorerDriver();
                    driver.get("http://yahoo.com");
                    }
    }

遵循当前的错误代码。 (我删除了这篇文章的IP)。

Started InternetExplorerDriver server (64-bit)
3.9.0.0
Listening on port 35599
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:35599
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'DESKTOP-BSN3U8P', ip: '', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '9.0.4'
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 firefoxöffner.main(firefoxöffner.java:23)
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:35599
    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.base/java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.base/java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.base/java.net.PlainSocketImpl.connect(Unknown Source)
    at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
    at java.base/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

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

看起来已知问题,请降级IEDriverServer并尝试。看看https://github.com/SeleniumHQ/selenium/issues/5519