O'Reilly logo

Selenium Testing Tools Cookbook by Unmesh Gundecha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Identifying and handling frames by their content

While working with frames, you will find that the id or name attributes are not defined. Still frames can be identified by using their index. This may not be a reliable way when applications are dynamic and there is a need to ensure that the correct frame is activated.

In this recipe, we will identify frames by the content of the document loaded in these frames to make tests more reliable.

How to do it...

Let's create a test that will get all the <frame> elements in a document and then iterate through this list to find out the desired frame as follows:

@Test public void testFrameByContents() { //Get all frames on the Page, created with <frame> tag List<WebElement> frames = driver.findElements(By.tagName("frame")); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required