In certain situations, developers neither assign a name
attribute nor provide a title to the page displayed in a window. This becomes more complex when a test needs to deal with multiple windows open at the same time and identify the desired window.
As a workaround to this problem, we can check the contents of each window returned by the driver.getWindowHandles()
method to identify the desired window.
Let's create a test that retrieves the handles of all the open windows in the current driver context. It will then iterate through this list, switching to the window and then checking for the content, which will help in identifying the correct window, as shown in the following code example:
@Test public void testWindowUsingContents() { // Store WindowHandle of parent browser window String currentWindowId = driver.getWindowHandle(); // Clicking Chat Button will open Chat Page in a new child window driver.findElement...