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")); ...

Get Selenium Testing Tools Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.