Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium javascript错误_Javascript_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Selenium javascript错误

Selenium javascript错误,javascript,java,selenium,selenium-webdriver,Javascript,Java,Selenium,Selenium Webdriver,selenium有时会给出以下错误。但在某些情况下,相同的代码会通过。我应该捕获异常并绕过吗?穿越的解决方案是什么 [31morg.openqa.selenium.JavascriptException: waiting for doc.body failed Command duration or timeout: 0 milliseconds at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ

selenium有时会给出以下错误。但在某些情况下,相同的代码会通过。我应该捕获异常并绕过吗?穿越的解决方案是什么

      [31morg.openqa.selenium.JavascriptException: waiting for doc.body failed
  Command duration or timeout: 0 milliseconds
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:582)
java代码是

ExpectedCondition<Boolean> pageLoad = new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            return ((JavascriptExecutor) driver).executeScript(
                    "return document.readyState").equals("complete");
        }
    };
    WebDriverWait wait = new WebDriverWait(driver, 40);
    wait.until(pageLoad);
ExpectedCondition pageLoad=新的ExpectedCondition(){
@凌驾
公共布尔应用(WebDriver驱动程序){
返回((JavascriptExecutor)驱动程序).executeScript(
“return document.readyState”)。等于(“完成”);
}
};
WebDriverWait wait=新的WebDriverWait(驱动程序,40);
等待.直到(页面加载);

如果要等待页面加载,可以使用以下代码

var wait = new WebDriverWait(driver, timeSpan.fromSeconds(30));
wait.until(d => ((IJavaScriptExecutor)d).executeScript("return document.readyState").equals("complete"));

您提供的解决方案是.net,它与上面Java中的代码等效。您的代码似乎是正确的。你能不能延长时间,看看你是否仍然会出错?