wait for “loading” icon to disappear from the page

前端 未结 3 1394
不知归路
不知归路 2021-01-21 14:47

we are doing automation for web application and most of the scenario getting loading icon will appear at center of the page .. we need to wait for dis appear to loading icon

相关标签:
3条回答
  • 2021-01-21 15:16

    You can also wait till the ajax calls have been completed. Loading wheel disappears when all the ajax calls have completed (in most of the scenarios):

    WebDriverWait wait = new WebDriverWait(d, timeOutSeconds);
    wait.until(waitForAjaxCalls()); 
    
    public static ExpectedCondition<Boolean> waitForAjaxCalls() {
            return new ExpectedCondition<Boolean>() {
                @Override
                public Boolean apply(WebDriver driver) {
                    return Boolean.valueOf(((JavascriptExecutor) driver).executeScript("return (window.angular !== undefined) && (angular.element(document).injector() !== undefined) && (angular.element(document).injector().get('$http').pendingRequests.length === 0)").toString());
                }
            };
        }
    
    0 讨论(0)
  • 2021-01-21 15:27

    Explicit Wait should help:

    public static String waitForElementNotVisible(int timeOutInSeconds, WebDriver driver, String elementXPath) {
        if ((driver == null) || (elementXPath == null) || elementXPath.isEmpty()) {
    
            return "Wrong usage of WaitforElementNotVisible()";
        }
        try {
            (new WebDriverWait(driver, timeOutInSeconds)).until(ExpectedConditions.invisibilityOfElementLocated(By
                    .xpath(elementXPath)));
            return null;
        } catch (TimeoutException e) {
            return "Build your own errormessage...";
        }
    }
    
    0 讨论(0)
  • 2021-01-21 15:30

    I have recently faced this issue. My solution might sound hacky but it worked pretty well in my case:

    public static void loadingWait(WebDriver driver, WebElement loader) {
        WebDriverWait wait = new WebDriverWait(driver, 5000L);
        wait.until(ExpectedConditions.visibilityOf(loader)); // wait for loader to appear
        wait.until(ExpectedConditions.invisibilityOf(loader)); // wait for loader to disappear
    }
    

    you can call this method after clicking on submit button. You have to pass driver, and loader web element to this method.

    0 讨论(0)
提交回复
热议问题