Requirement: Bydefault, search for webelement on main window, if found perform action else search for webelement inside iframes and perform required action
Selenium 3.141
'''
WebElement el = driver.findElement(By.xpath("//*[contains(text(),'here')]"));
boolean displayFlag = el.isDisplayed();
if(displayFlag == true)
{
sysout("element available in main window")
el.click();
}
else
{
for(int f=0;f<10;f++)
{
sysout("element available in frameset")
switchToFrame(frameName[f]);
el.click();
System.out.println("Webelement not displayed");
}
}
'''
My script is failing at first line itself. It is trying to find element in main window but element is actually available in iframe.
But the requirement is to search first in main window and then only navigate to iframes. How to handle such usecase?
Any suggestion would be helpful? Thank you.