JS Testing Academy · QA Demo Site

Frames

Two iframes on one page. You cannot touch anything inside them until you switch into the frame – and you must switch back afterwards.

Frame 1

Frame 2 (smaller)

Inside each frame there is a heading with the id frame-heading and a button with the id frame-button.

This text is outside the frames.

Practice tasks

  1. Switch into frame 1 and assert the heading text is This is frame 1.
  2. Click the button inside frame 1 and assert the message inside that frame appears.
  3. Switch back to the main page with switchTo().defaultContent() and read the outside text.
  4. Switch into frame 2 and assert its heading is different from frame 1.
  5. Count how many iframes are on the page.
Sample automation code
driver.switchTo().frame("frame1");
Assert.assertEquals(driver.findElement(By.id("frame-heading")).getText(), "This is frame 1");
driver.findElement(By.id("frame-button")).click();
driver.switchTo().defaultContent();

Assert.assertTrue(driver.findElement(By.id("outside-message")).isDisplayed());
Assert.assertEquals(driver.findElements(By.tagName("iframe")).size(), 2);