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")); //In this example frame in the middle is activated by checking the //contents //Activate frame and check if it has the desired content. If found perform the operations //if not, then switch back...