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.
do{
// 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.do{driver.navigate().refresh();}while(!driver.findElement(By.id("gbqfq")).isDisplayed());
Happy Selenium Webdrivering!!!
ReplyDeleteI have tried using your method in my application.My test case is failing instead of refreshing the page until the element exists.Please help
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.
ReplyDeleteI have a scenario. I send an email to my gmail account from application. It takes varying time.
ReplyDeleteNow 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
hello! how to refresh 10 times? do while is an endless loop going to be in my case
ReplyDelete