WindowIDs stored in Set | Selenium Forum
M
Posted on 12/08/2016
Hi sir,

Request you to please suggest why window IDs are stored specifically in a set by Selenium and not in a list. I remember watching in the video that In set unique elements are stored and window IDs are unique. But even though the window Ids are unique, they can be stored in a list also.

Is there any specific reason that window Ids are stored in a set by Selenium.

Thank you.

M
Replied on 12/08/2016

As per java doc, it returns Set , check below

[code:1f1gvqup]getWindowHandles
java.util.Set<java.lang.String> getWindowHandles()

Return a set of window handles which can be used to iterate over all open windows of this WebDriver instance by passing them to switchTo().WebDriver.Options.window()
Returns:A set of window handles which can be used to iterate over all open windows.[/code:1f1gvqup]

You can convert later to Array of Strings if you need, if you dont want to use iterator

Set<String> ids= driver.getWindowHandles();
String mainWin= (String) ids.toArray()[0];
String popWin= (String) ids.toArray()[1];