如下代码,有时候并不能工作:

WebDriverWait wait = new WebDriverWait(dr, 60);
     wait.until(new ExpectedCondition<Object>() {

         @Override
         public Object apply(WebDriver webDriver) {
             System.out.println("当前ajax active 数量: " + ((JavascriptExecutor) webDriver).executeScript("return jQuery.active"));
             return ((JavascriptExecutor) webDriver).executeScript("return jQuery.active==0");
         }
     });

有时候会报错,

org.openqa.selenium.JavascriptException: javascript error: jQuery is not defined
  (Session info: chrome=102.0.5005.63)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'

而有时候就不会

另外一种等待 ajax 结束就是 等待某个元素出现,或者可点击,还有别的方法么?


↙↙↙阅读原文可查看相关链接,并与作者交流