Get all the frames available on the page

10 November, 2014
We can get the the list of all frame (names) available on a page using the below methods:

 
//Make sure you are in default frame
driver.switchTo().defaultContent();
List framesetList=driver.findElements(By.tagName("frame"));
if(framesetList.size()>0){
     for(WebElement framename :framesetList){
       System.out.println("Frame with name:" + framename.getAttribute("name")+" found.");
     }
}
else {
     System.out.println("No frame found");
} 

 
public void getIframe(final WebDriver driver, final String id) {
    final List iframes = driver.findElements(By.tagName("iframe"));
    for (WebElement iframe : iframes) {
        if (iframe.getAttribute("id").equals(id)) {
        // TODO your stuff.
        }
    }
}

No comments:

Post a Comment