{
getUtil().waitUntilCondition(new ExpectedCondition<WebElement>()
{
public WebElement apply(WebDriver driver)
{
WebElement element = null;
for (int i = 0; i < locators.length; i++) {
try {
element = driver.findElement(locators[i]);
} catch (NotFoundException e) {
// This exception is caught by WebDriverWait
// but it returns null which is not necessarily what we want.
if (all) {
return null;
}
continue;
}
// At this stage it's possible the element is no longer valid (for example if the DOM has
// changed). If it's no longer attached to the DOM then consider we haven't found the element
// yet.
try {
if (element.isDisplayed()) {
if (!all) {
return element;
}
} else if (all) {
return null;