Selenium webdriver has given some specific features to handle multiple windows in a browser. For example, we have WindowA. Clicking on a link of WindowA will open a WindowB and clicking on a link of WindowB will open a new WindowC.
Now we want to move from WindowA to WindowC, the code (Java) will be,
String Parent_Window=driver.getWindowHandle();
for (String Child_Window : driver.getWindowHandles())
{
driver.switchTo().window(Child_Window);
}
driver.getWindowHandle() :: returns the current window position.
driver.getWindowHandles() :: Rturns all the open windows referrence.
Using For statement driver will hover all window and stop to the last WindowC. If we want to move back to WindowA, we need another statement,
driver.switchTo().window(Parent_Window);
After moving to a window, we can do any other operation on that window and then moves to other windows.
This comment has been removed by a blog administrator.
ReplyDeleteGreat Information.
ReplyDeleteThank you.
DeleteHi Nadim,
ReplyDeleteI am having scenario where Child window is having one more child window. Could you please guide me how to handle this?
Thanks
R G Bhat
Please use different driver variable for more than one child window.
DeleteThank You Nadim
ReplyDelete