Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

How to handle frames in WebDriver?

In WebDriver, a frame is an HTML document embedded inside another. You can switch between frames using the `switchTo()` method and then perform actions on the elements inside the frame. Once you finish your work in that frame, you can return to the default content by calling `switchTo().`

Here are the steps to handle frames in WebDriver:

  • Identify the frame by its name, index, ID, or web element.
  • Use the switchTo().frame() method to change the current frame.
  • You can perform actions on the elements inside the frame.
  • Use the switchTo().defaultContent() method to return to the default content.

The following example demonstrates how to switch to a frame by using its ID and performing actions on the elements inside of it:

// Assume we have a frame with ID 'frame1'

// Switch to the frame using its ID
driver.switchTo().frame("frame1");

// Perform actions on the elements inside the frame
WebElement element = driver.findElement(By.id("elementInsideFrame"));
element.click();

// Switch back to the default content
driver.switchTo().defaultContent();

It is important to remember that if a frame is nested inside another frame, you will need to switch to each frame in order and then back again in reverse order.

LambdaTest

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing
LambdaTest

Earn resume-worthy Selenium certifications that help you land a top job.

Learn More
LambdaTest

Test your web or mobile apps

Test orchestration and execution cloud of 3000+ browsers and OS

Support

24/7 support

Security

Enterprise grade security

Cloud

Fastest test execution cloud