Reputation: 161
I have a very complex html page.
<html>
<head></head>
<body>
<iframe> A </iframe>
<table>
<div>
<span>
<div> <iframe> B </iframe> </div>
<style>
<div>
<div>
When I try to locate an element in the iframe A it is getting to another iframe. I tried switching to the iframe using driver.switchTo().frame(0) but no use.
When I try to get all the iframes using the findElements method it is returning only one iframe (B).
Upvotes: 0
Views: 1516
Reputation: 5799
The answer depends on what you want to do with the list of iframes.
If you want all the list, you can try using recursive function.
public void getAlliFrames(){
List<WebElement> iframes = driver.findElements(By.tagName("iframe"));
if(iframe.count() > 0){
driver.switchTo().frame(iframe.get(0));
getAlliFrames();
}else{
System.out.println("No more iframes");
}
}
PS: This is an untested code and just provided for your reference.
Upvotes: 2