How to wait for an element or for an alert at the same time

I’m performing a search and if the search has no documents, an alert will be displayed and if it has results, I have to capture results

How can I wait for either alert or Search results element.

ydskumar Default Asked on April 7, 2015 in Selenium WebDriver.
Add Comment
1 Answer(s)

Try this generic wait code by passing both expected conditions

public boolean waitForPageLoad(int waitTimeInSec, ExpectedCondition<Boolean>… conditions) {
boolean isLoaded = false;
Wait<WebDriver> wait = new FluentWait<>(driver)
.withTimeout(waitTimeInSec, TimeUnit.SECONDS)
.ignoring(StaleElementReferenceException.class)
.pollingEvery(2, TimeUnit.SECONDS);
for (ExpectedCondition<Boolean> condition : conditions) {
isLoaded = wait.until(condition);
if (isLoaded == false) {
//Stop checking on first condition returning false.
break;
}
}
return isLoaded;
}

amitjain Supporter Answered on April 8, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.