我有一个Java WebDriver驱动的Selenium执行,它在列表上循环以在文本框中输入其他信息并使用FirefoxDriver发送它。
在第10次或第11次迭代后,在一台非常可重现的计算机上,调用 findElement(By.id("mi4"))会引发一个UnreachableBrowserException。
findElement(By.id("mi4"))
UnreachableBrowserException
Jun 29, 2012 1:52:02 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect Information: I/O exception (java.net.BindException) caught when connecting to the target host: Address already in use: connect Jun 29, 2012 1:52:02 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect Information: Retrying connect Jun 29, 2012 1:52:02 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect Information: I/O exception (java.net.BindException) caught when connecting to the target host: Address already in use: connect ... Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died. Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 15:28:49' System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_04' Driver info: driver.version: RemoteWebDriver at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:467) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:242) Caused by: java.net.BindException: Address already in use: connect at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820) at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:337) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:297) at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:136)
没有任何第三方程序在任何端口上侦听。但是,我使用了FirefoxDriver的两个实例,这意味着并行打开了两个Firefox实例/ Windows,它们在Win7机器上可以正常工作,而在Windows XP机器上会出现上述问题。
我将Firefox 13与selenium2.24.1一起使用。
听起来好像您用完了临时端口,因为您要一遍又一遍地进行迭代。在Windows XP中,临时TCP端口的默认最大数量为5000。尝试按照此处 Microsoft KB文章中的分辨率增加限制。重新启动机器。这个解决方案对我有用。