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
- Switch into the parent frame and assert its text.
- From there switch into the child frame and assert the child text.
- Go back to the main page using
defaultContent()and then reach the child frame again in one go. - 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
const child = page.frameLocator('#parent-frame').frameLocator('#child-frame');
await expect(child.locator('#child-text')).toContainText('Child frame');