N NextGen Virtual Academy
AD Administrator Learning Manager
SELENIUM WEBDRIVER · PRACTICE LAB

Frames Practice Lab

Practice switching between frames, nested frames and the main document using Selenium WebDriver.

LAB FRAME
OBJECTIVE

What You Will Practice

  • Switch to a frame using index.
  • Switch to a frame using name or ID.
  • Switch using a WebElement.
  • Return to the parent document.
  • Work with nested frames.
01

Simple Frame

Switch into this frame and interact with the elements inside it.

FRAME
Selenium Hint driver.switchTo().frame("simpleFrame");
02

Frame Using WebElement

Locate the iframe as a WebElement and switch into it.

WEBELEMENT
Selenium Hint WebElement frame = driver.findElement(By.id("webElementFrame")); driver.switchTo().frame(frame);
03

Nested Frames

Practice switching from the parent frame into a child frame.

NESTED
" >
Selenium Hint driver.switchTo().frame("outerFrame");

driver.switchTo().frame("innerFrame");
04

Return to Main Document

After working inside a frame, return to the main HTML document.

DEFAULT CONTENT

Main Document Area

This section is outside all frames.

Selenium Hint driver.switchTo().defaultContent();
QUICK REFERENCE

Selenium Frame Commands

By Index
driver.switchTo()
      .frame(0);
                    
By Name / ID
driver.switchTo()
      .frame("frameName");
                    
By WebElement
WebElement frame =
    driver.findElement(
        By.id("frameId")
    );

driver.switchTo()
      .frame(frame);
                    
Return to Main Page
driver.switchTo()
      .defaultContent();