I need to wait until some element will be displayed on page.
I have created method in which I have used wait.until(ExpectedConditions.visibilityOfElementLocated())
:
public void waitForElementPresentBy(By locator) {
try{
wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
}catch (Exception e){
Assert.fail("Element was not become visible");
}
}
wait
object was initialized in next way - I have set 300 seconds:
wait = new WebDriverWait(webDriver, 300);
But this method is not executed correctly. It does not wait until my element will be visible.
When I added Thread.sleep(3000)
, it helped.
But how to waiting for element not adding sleep()
?