Sunday, February 24, 2013

Handling child windows using Web Driver

//Click on link which will open new Link

             driver.findElement(By.linkText("Search settings page")).click();

// Now we have two windows and store them in to object array

            Object[] currentWindow =driver.getWindowHandles().toArray();

//In the array, first index is Parent window next is child window

            String ParentWindow=currentWindow[0].toString();
            String ChildWindow=currentWindow[1].toString();

//To work on child window

            driver.switchTo().window(ChildWindow);

//Now you are in child window, If you want go back to parent window

            driver. close()   // It will close the child window.  (Optional.If you dont want to close the first window, this step is not required.)

            driver.switchTo().window(ParentWindow);
           

No comments:

Post a Comment