Identifying and handling a window by its title

Many a time, developers don't assign the name attribute to windows. In such cases, we can use its window handle attribute. However, the handle attributes keep changing and it becomes difficult to identify the window, especially when there is more than one window open. Using the handle and title attributes of the page displayed in a window, we can build a more reliable way to identify child windows.

In this recipe, we will use the title attribute to identify the window and then perform operations on it.

How to do it...

We will create a test that retrieves the handles of all the open windows in the current driver context. We will iterate through this list and check the title matching the criteria, as follows: ...

Get Selenium Testing Tools Cookbook - Second Edition 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.