有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Selenium Webdriver HtmlUnitDriver:UnreachableBrowserException

我随机得到一个org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.错误,也就是说,同一代码中的同一输入并不总是发生错误。守则:

public class PortalListingCallable implements Callable<Listing>  {
    private WebDriver driver;
    private WebElement event;

    public PortalListingCallable(WebElement event) {
        driver = new HtmlUnitDriver();
        this.event = event;
    }

    public Listing call() {
        //System.out.println("in PortalLisingCallable");
        Listing newListing = ListingFactory.createListing(
                 new PortalScheduleEventsEvent(driver, event.findElements(By.tagName("td"))).parse());
        driver.close();
        return newListing;
    }
}

我也试过Listing newListing = ListingFactory.createListing(new PortalScheduleEventsEvent(new HtmlUnitDriver(), event.findElements(By.tagName("td"))).parse());

这个类实现了Callable,所以它被多个线程调用,但是数据是独立的。该守则:

while (webElementsQueue.peek() != null) {
        Callable<Listing> callable = new    
    PortalListingCallable(webElementsQueue.poll());
    //Future<Listing> future = executor.submit(callable);
    Future<Listing> future = executor.submit(new Callable<Listing>() {
        @Override
        public Listing call() throws Exception {
            try {
                return callable.call();
            } catch (Exception e) {
                e.printStackTrace();
                throw e;
            }
        }
    });

    listingQueue.offer(future);
}

我怀疑这与在多个线程中调用有关,但由于HtmlUnitDriver的每个实例都是孤立的,所以我不确定如何调用

以下是例外情况:

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.46.0', revision: '61506a4624b13675f24581e453592342b7485d71', time: '2015-06-04 10:22:50'
System info: host: '955PC', ip: 'x.x.x.x', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_40'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:269)
    at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:188)
    at org.openqa.selenium.remote.RemoteWebElement.findElementsByTagName(RemoteWebElement.java:265)
    at org.openqa.selenium.By$ByTagName.findElements(By.java:324)
    at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:164)
    at autoschedtwo.portal.PortalListingCallable.call(PortalListingCallable.java:31)
    at autoschedtwo.portal.PortalListingCallable.call(PortalListingCallable.java:17)
    at autoschedtwo.portal.PortalDriver$1.call(PortalDriver.java:40)
    at autoschedtwo.portal.PortalDriver$1.call(PortalDriver.java:36)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:26014 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Build info: version: '2.46.0', revision: '61506a4624b13675f24581e453592342b7485d71', time: '2015-06-04 10:22:50'
System info: host: '955PC', ip: 'x.x.x.x', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_40'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:76)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
    ... 13 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:26014 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:143)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:89)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:134)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:67)
    ... 14 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
    ... 27 more

共 (0) 个答案