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

Popular posts from this blog

Jenkins CICD in One Page

Why do we need a build tool?

Deutsche Bank Interview Questions - 2024