Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
2.0k views
by Contributing Tester (92 points)
edited by

In Selenium getWindowHandles() method returns Set, what is the reason?

1 Answer

1 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer

This is the defination of getWindowHandles function from RemoteWebDriver class.

 

public Set<String> getWindowHandles() {
    Response response = execute(DriverCommand.GET_WINDOW_HANDLES);
    Object value = response.getValue();
    try {
      List<String> returnedValues = (List<String>) value;
      return new LinkedHashSet<>(returnedValues);
    } catch (ClassCastException ex) {
      throw new WebDriverException(
        "Returned value cannot be converted to List<String>: " + value, ex);
    }
  }
 
As you can see, List<String> is covered to LinkedHashSet. Sometimes DriverCommand.GET_WINDOW_HANDLES might return blank values or duplicate values. By converting that into set, we can avoid that.
 
Hope that answerd your question.
by Contributing Tester (92 points)
Thanks! Resolved my query.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...