Selenium - Use Explicit Waits for checking elements quickly disappear like loading icon - The Koch Family
The Koch Family The Koch Family

Latest news

جاري التحميل ...

Selenium - Use Explicit Waits for checking elements quickly disappear like loading icon

I have a table that is displayed a list of competence groups. When I click on a competence group, it will display a table that contains a lot of criteria belong to the competence group. Each times I click on a competence group, a "loading" icon is displayed while waiting for all criteria is fully displayed.

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

I tried to write a Selenium test to make sure this behavior is covered. I saw that the loading icon element is always available on DOM tree because I just used Jquery to handle its displaying. Beside that, the loading icon is appeared dynamically and quickly disappear afterwards. It is hard to checking the visibility on GUI of loading icon. By normal way that I frequently used, the code looks like:

public boolean isLoadingIconDisplayed() {
List<WebElement> loadingIcons = driver.findElements("loading"));
for(WebElement loadingIcon: loadingIcons){
return false;
return true;

But, it did not work. I thought that I need a waiter likes a listener to check this loading appearing before clicking on table. I found the solution with Explicit Waits:
public boolean isLoadingIconDisplayed() {
try {
(new WebDriverWait(driver, 3)).until(ExpectedConditions.invisibilityOfElementLocated("loading")));
return true;
} catch (Exception e) {
return false;

"An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code".




If you like the content of our blog, we hope to stay in constant communication, just enter your email to subscribe to the blog's express mail to receive new blog updates, and you can send a message by clicking on the button next ...

إتصل بنا

About the site

author The Koch Family <<  Welcome! I'm so glad that you stopped by Your Modern Family blog. Together, we will talk about raising kids, organizing the home and saving money! and Tips & tricks and more…

< Learn more ←

Blog stats

Sparkline 2513183

All Copyrights Reserved

The Koch Family