1

In one application, there is a child window, which opens another window. In total there are three windows. The window handles and the titles of each window are dynamic, they change every session.

So I stored the handles of the parent window and the first child window, then I called getWindowHandles method, stored all handles in a set, removed parent window and first child window. The remaining window handle in the set will be the third window handle.

Set<String> windowHandles = uiDriver().getDriver().getWindowHandles(); windowHandles.remove(parentHandle); windowHandles.remove(firstChildHanlde); String thirdChildHandle = windowHandles.toString(); 

It would be of great help if you can help me on how to get the child window handle in a more convenient way.

4
  • What's wrong with the way you've done it? Commented Dec 16, 2019 at 15:32
  • You could also keep track of handles with your own arraylist and use contains() to add new handles when iterating through the set. If your array does not contain it, you add it. Commented Dec 16, 2019 at 22:55
  • @JeffC my code won't work if in case four windows open Commented Dec 17, 2019 at 5:37
  • @pcalkins Thanks for the suggestion, having an array list is more convenient as I could store the handles in order and get a specific handle using the index Commented Dec 17, 2019 at 5:39

1 Answer 1

1

For a more generic method of handling windows handles you can get the Set of windows handles before you perform some action that opens more windows, perform the action, then get the Set of window handles afterwards, and then remove the "before" Set from the "after" Set. What remains are the windows that were opened during the action.

Set<String> beforeWindowHandles = uiDriver().getDriver().getWindowHandles(); // do something that opens a window Set<String> afterWindowHandles = uiDriver().getDriver().getWindowHandles(); afterWindowHandles.removeAll(beforeWindowHandles); 

Now afterWindowHandles contains only the newly opened windows.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.