I have an application with multiple iframes in the same screen. These iframes have different names every session, so I would like to search within the application for a button within one of the iframes with the name "Pesonal". This iframe-name should be saved to be used in another method. Anybody an idea how to do this?
Please close / delete this topic as I have found the solution:
public WebElement findElement(By locator) {
driver.switchTo().defaultContent();
//list all iframes
List<WebElement> iframeList = driver.findElements(By.tagName(("iframe")));
final List<WebElement> foundElements = new ArrayList<>();
iframeList.forEach(iframe -> {
driver.switchTo().frame(iframe);
List<WebElement> foundElementList = driver.findElements(locator);
if (foundElementList.size() > 0) {
foundElements.addAll(foundElementList);
} else driver.switchTo().defaultContent();
});
return foundElements.get(0);
}