JS Testing Academy · QA Demo Site

Nested Frames

A frame inside a frame. To reach the inner text you have to switch twice, in order.

The parent frame contains the text Parent frame and a child iframe with the id child-frame, which contains the text Child frame.

Practice tasks

  1. Switch into the parent frame and assert its text.
  2. From there switch into the child frame and assert the child text.
  3. Go back to the main page using defaultContent() and then reach the child frame again in one go.
  4. Use switchTo().parentFrame() to go from the child back to the parent.
Sample automation code
driver.switchTo().frame("parent-frame");
Assert.assertTrue(driver.findElement(By.id("parent-text")).getText().contains("Parent frame"));

driver.switchTo().frame("child-frame");
Assert.assertTrue(driver.findElement(By.id("child-text")).getText().contains("Child frame"));

driver.switchTo().parentFrame();     // back to the parent frame
driver.switchTo().defaultContent();  // back to the page