Selenium – wait for “loading” icon to disappear from the page


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

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

Example : we are having search functionality their in most of scenario we are getting this loading icon.

selenium webdriver we are using: id we are getting for loading to complete is id= "loading"..please any give the solutions for the above issues am facing.

we have different functionality like click & sendkeys

Best Solution

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
        return null;
    } catch (TimeoutException e) {
        return "Build your own errormessage...";
Related Question