与远程浏览器通信时出错。它可能已经死了。 Selenium Web驱动程序

时间:2014-04-11 22:09:33

标签: firefox selenium selenium-webdriver

这是我的错误日志:

Apr 12, 2014 3:27:46 AM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: I/O exception (java.net.SocketException) caught when connecting to the target host: Permission denied: connect
Apr 12, 2014 3:27:46 AM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: Retrying connect
Apr 12, 2014 3:27:46 AM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: I/O exception (java.net.SocketException) caught when connecting to the target host: Permission denied: connect
Apr 12, 2014 3:27:46 AM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: Retrying connect
Apr 12, 2014 3:27:46 AM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: I/O exception (java.net.SocketException) caught when connecting to the target host: Permission denied: connect
Apr 12, 2014 3:27:46 AM org.apache.http.impl.client.DefaultRequestDirector tryConnect
INFO: Retrying connect
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'prgi-PC', ip: '192.168.1.9', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:589)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
    at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:187)
    at org.openqa.selenium.remote.RemoteWebElement.findElementsByTagName(RemoteWebElement.java:264)
    at org.openqa.selenium.By$ByTagName.findElements(By.java:323)
    at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:163)
    at com.sai.kiran.Test.main(Test.java:155)
Caused by: java.net.SocketException: Permission denied: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:83)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:178)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144)
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:131)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
    at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
    at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:322)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:301)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
    at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:568)
    ... 6 more

CODE:

FirefoxProfile profile = new FirefoxProfile();

String path="C:\\Users\\prgi\\Downloads\\listShack";
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", path);

profile.setPreference("browser.download.manager.alertOnEXEOpen", false);

profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/msword,application/csv,text/csv,image/png ,image/jpeg");

profile.setPreference("browser.download.manager.showWhenStarting",
false);

profile.setPreference("browser.download.manager.focusWhenStarting",
false);
//profile.setPreference("browser.download.useDownloadDir",true);
profile.setPreference("browser.helperApps.alwaysAsk.force",
false);

profile.setPreference("browser.download.manager.alertOnEXEOpen", false);

profile.setPreference("browser.download.manager.closeWhenDone", false);

profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.useWindow",
false);

profile.setPreference("browser.download.manager.showWhenStarting",false);

profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting",
false);

profile.setPreference("pdfjs.disabled", true);

WebDriver driver = new FirefoxDriver(profile);

从这里开始管理我的元素..

注意:它每天24小时不间断工作两天,今天我经常收到此错误。

4 个答案:

答案 0 :(得分:10)

<强>问题

我在Windows 7中本地运行InternetExplorerDriver时遇到同样的问题 - (IEDriverServer_Win32_2.42.0.zip)

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.

当我在TaskManager下检查正在运行的进程时,有多个IEDriverServer.exe进程正在运行,尚未正确清理。

<强>解决方案

运行以下命令,杀死所有正在运行的IEDriverServer.exe进程,并解决了这个问题(对我而言)。

taskkill /F /IM IEDriverServer.exe

答案 1 :(得分:0)

我按照这些步骤解决了问题:

  1. 获取firefox个人资料名称

    • 在运行窗口firefox.exe -P上尝试此命令 firefox.exe -P firefox.exe -profilemanager
  2. 以上命令之一将打开弹出窗口,说明默认配置文件的名称,这是默认的“默认”

    1. 使用下面提到的代码获取firefox驱动程序

      ProfilesIni allProfiles = new ProfilesIni();
      FirefoxProfile myProfile = allProfiles.getProfile("default");
      myProfile.setAcceptUntrustedCertificates(true);
      myProfile.setAssumeUntrustedCertificateIssuer(true);
      driver = new FirefoxDriver(myProfile);
      

答案 2 :(得分:0)

对于我使用以1开头的端口而不是接近默认端口值5555的端口,导致我出现此错误。将节点端口从1234更改回5558已解决了该问题。不确定端口是如何工作的,但似乎1234不稳定

答案 3 :(得分:-3)

Please try to replace exe path with below command

File file = new File("IE DriverServer.exe path");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());