How to handle multiple windows in Selenium
- We can use the mehtod driver.switchTo.window(WindowHandle);
- Selenium assigns a Unique Id to each open window in Browser. This id is called window handle.
You can get the window handle of all open windows by using driver.getWindowHandles() method which returns a Set of Window Handles.
You can iterate this set to switch to the corresponding window.
Example1: By getting parent window handle
Example 2: By using a count variable
Example 2: Get the title of the page while iterating the Set and switch to the window with desired title.
Comments
Post a Comment