So, the page is filled with a lot of similar properties like these two elements below. Examples:
I'll show how I would go about it, but the problem might be a problem with selenium not always returning isDisplayed() correctly depending on the element type.
public WebElement getFirstVisibleElement(List<WebELement> elements) {
for (WebElement ele : elements)
if (ele.isEnabled() && ele.isDisplayed())
return ele;
return null;
}
A more reliable method of checking if a web element is displayed is to check its dimensions (height and width). If they are both zero, it's not displayed.
public WebElement getFirstVisibleElement(List<WebELement> elements) {
for (WebElement ele : elements)
if (ele.isEnabled() && ele.getSize().getHeight() > 0 && ele.getSize().getWidth() > 0 )
return ele;
return null;
}