Let's say I am trying to find an element named element0
,
driver.FindElement(element0).Click;
Thread.Sleep(5000);
Depending on my WiFi speed, element0
could take anywhere from 5000 to 10000 milliseconds to show up.
Having to constantly change the value in Thread.Sleep()
would defeat the purpose of automation.
Surrounding it around a try catch block could work:
try
{
driver.FindElement(element0).Click;
Thread.Sleep(5000);
}
catch(org.openqa.selenium.NoSuchElementException e)
{
driver.FindElement(element0).Click;
Thread.Sleep(5000);
}
But if element0
is still not present after catching org.openqa.selenium.NoSuchElementException e
then it would just throw another one of the same errors.
Is there a better way of telling my code to sleep?
Could I iterate over driver.FindElement(element0).Click
in a loop until element0
is present?