Next-Gen App & Browser
Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles
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:
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.
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.