Wednesday, September 10, 2014

How to continue refreshing a page until the element is loaded

Sometimes we need to continue refreshing the page until an specific element is loaded. In that case we need to write some extra code beside selenium webdriver command.

We can use do…While() loop using the specific element as locator and the function “isDisplayed()” to detect that the element is appeared. We run the loop until we get the element loaded on the page. Every time we execute the refresh() method under the loop.

            // Reload the page

}while(the specific element is not displayed);

In Java,

I think this will help those who are fighting with element loading problem.
Happy Selenium Webdrivering!!!


  1. I have tried using your method in my application.My test case is failing instead of refreshing the page until the element exists.Please help

  2. Please use the appropriate while condition. In my case it was working. You can share the code here if you have not any problem. I am ready to help. Thank you.

  3. I have a scenario. I send an email to my gmail account from application. It takes varying time.
    Now I m trying to search the email with an unique name given in content and refresh it until that text appears in the content , then click on the email. I tried with recursive functions. Please do help me