Wait for the Download icon to disappear from the page.

we are doing automation for a web application and most of the script gets a download icon in the center of the page. We need to wait for the download icon to appear.

<div id="loading" style="display: none; visibility: hidden;">
<div></div>
<div></div> 

Example: we have a search function, in most cases we get this download icon.

selenium webdriver that we use: the id that we get to download to complete is id = "loading" .. please provide solutions to the above problems.

we have different functions like click and sendkeys

+2
source share
3 answers

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...";
    }
}
+4
source

. , :

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
}

. - .

+1

ajax. , ajax ( ):

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

Source: https://habr.com/ru/post/1546888/


All Articles