RemoteWebDriver在调用switchTo()方法时导致stackoverflow错误

时间:2018-06-18 15:55:39

标签: selenium stack-overflow xvfb remotewebdriver

Selenium版本:3.7.1

我正在自动化java swing应用程序并使用远程Web驱动程序,如下所示:

DesiredCapabilities dc = new DesiredCapabilities();
dc.setBrowserName("java");
dc.setVersion(" ");
dc.setJavascriptEnabled(true);
dc.setPlatform(Platform.ANY);
javaDriverTest = new RemoteWebDriver(new URL("docker container url"), dc);

除了以下内容外,一切正常:

javaDriverTest.switchTo().window(windowName);

我随后得到了这个错误:

java.lang.StackOverflowError
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
    at java.net.SocketInputStream.read(SocketInputStream.java:171)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
    at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
    at org.apache.http.impl.BHttpConnectionBase.fillInputBuffer(BHttpConnectionBase.java:344)
    at org.apache.http.impl.BHttpConnectionBase.isStale(BHttpConnectionBase.java:364)
    at org.apache.http.impl.conn.CPoolProxy.isStale(CPoolProxy.java:114)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:208)
    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:138)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:86)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:161)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:657)
    at org.openqa.selenium.remote.RemoteWebDriver.getWindowHandles(RemoteWebDriver.java:505)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:962)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:963)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:963)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:963)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:963)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:963)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:963)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:963)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:963)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:963)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:963)

这并不是一直发生的。但是经常发生。知道如何修复它吗?

1 个答案:

答案 0 :(得分:0)

问题似乎与我启动应用程序的方式有关,即,我最初使用了以下内容:

export DISPLAY=:1.0
javaws -J -Dmarathon.agent=file:/root/Downloads/marathon-java-agent-5.1.4.0.jar.........

但是当我在命令中添加Xvfb时

Xvfb :1.0
export DISPLAY=:1.0
javaws -J -Dmarathon.agent=file:/root/Downloads/marathon-java-agent-5.1.4.0.jar.........

它解决了该问题。因此,我相信这个问题确实与RemoteWebDriver无关,而实际上与被测应用程序的启动方式有关。