Sunday, October 8, 2017

How to handle multiple windows in selenium ?

 Sometime when we click on any link then a window is opened and in our test case we have to perform some action on that opened window (called as child window) so first we need to switch on this child window then we can perform any action. Below code handle the multiple window.

        String parent_win = driver.getWindowHandle(); //store parent window in a string

        Now assume after click on any link a child window will be open.

        Set<String> child_win = driver.getWindowHandles(); // store all child windows in a string using Set interface.

       for (String child_Windows : child_win )
             {
             driver.switchTo().window(child_Windows); // switch to child window
             }

No comments:

Post a Comment