Skip to content
Advertisement

How to wait all ajax requests finished except “jQuery.active ==0”?

In fact, I’am working in webdriver, I want to make it to wait ajax finished. following is the code I got from searched websites:

public static void waitAjaxDone(WebDriver dr) {
    WebDriverWait wait = new WebDriverWait(dr, 60);
    wait.until(new ExpectedCondition<Object>() {
        @Nullable
        @Override
        public Object apply(@Nullable WebDriver webDriver) {
            return ((JavascriptExecutor)webDriver).executeScript("return jQuery.active==0");
        }
    });

}

we could see that the key code is “jQuery.active”, this may got the running ajax request count, but it now works for me, and my websites did not use jQuery but other js library.

is there other way to get the count of running ajax ? or is there a matched method in pure javascript to the “jQuery.active” ?

Advertisement

Answer

In fact, It is really hard to know whether the ajax requests is done, we could to send the ajax reqeust directly to get the response , then do the next steps

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement