In this session you will learn what are nested frames on a webpage and how to handle nested frames.
Please watch below basic session how to handle single frame so that it would be easy to understand this nested frames session
How to handle single frame on a webpage
https://studio.youtube.com/video/0tcP...
If you want to download the project/code, please download from below GitHub Repository
https://github.com/knowledgeshare-tec...
What is Nested iframe
An HTML iframe inside an another iframe is called Nested Iframe
To access elements of respective webelement in a iframe you have to switch to respective iframe
Switch to Frame
ByIndex driver.switchTo().frame(0)
By Name or ID driver.switchTo.frame(“Name or id of iframe”)
By WebElement driver.switchTo.frame(WebElement)
Switch to Main Frame / Parent Frame
driver.switchTo().parentFrame();
driver.switchTo().defaultContent();
Practice program on how to handle nested frame
============================================
package com.seleniumbasics;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class nested_iframes_Example {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", ".\\drivers\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.navigate().to("https://chercher.tech/practice/frames...");
driver.manage().window().maximize();
int number_of_iframes=driver.findElements(By.tagName("iframe")).size();
System.out.println("Number of iframes on a page : " + number_of_iframes);
driver.switchTo().frame("frame1");
System.out.println("Switched to frame1");
driver.findElement(By.xpath("//input[@type='text']")).sendKeys("test");
driver.switchTo().frame("frame3");
System.out.println("Switched to frame3");
driver.findElement(By.xpath("//input[@type='checkbox']")).click();
driver.switchTo().defaultContent();
System.out.println("Switched to main content");
driver.switchTo().frame("frame2");
System.out.println("Switched to frame2");
Select animals =new Select(driver.findElement(By.id("animals")));
animals.selectByIndex(2);
driver.switchTo().defaultContent();
System.out.println("Switched to default content7");
String main_text=driver.findElement(By.xpath("(//span)[3]")).getAttribute("innerHTML");
System.out.println(main_text);
}
}