Handle Multiple Windows in Selenium Webdriver in Simple ways

We can handle multiple windows in selenium webdriver using Switch To methods which will allow us to switch control from one window to another window.If you are working with web applications then you must have faced this scenario where you have to deal with multiple windows.

If you have to switch between tabs then also you have to use the same approach.  Using switch To method we can also handle frames and alerts with easy methods. I will focus on multiple windows as of now.

handle multiple windows in selenium webdriver

handle multiple windows in selenium webdriver


Before starting this section I will recommend you watch List and Set in Java which will help you to understand this concept in details.

In Selenium, we have the feature that we can get the window name of the current window.In Selenium, we have the getWindowName method that will return current window name in String form.


I have also published video on this which will give you the clear idea how this works.



Approach to handle multiple windows in selenium webdriver


We also have getWindowNames, which will return Set<String> it means the set of window name then we can iterate using Iterator. The set is part of Java collection which allows us to handle multiple sets of data dynamically.
Scenario 1- In some application, you will get some Pop up that is nothing but separate windows takes an example of naukri.com.
Therefore, in this case, we need to close the popup and switch to the parent window.

Complete program to handle multiple windows in selenium webdriver

First, we will switch to child window (pop up window) then we will close it and then we will switch to the parent window.


We can switch to the window using title and content also.

If you still have some query regarding this then comment in below section.

Thanks for visiting my blog. Keep in touch.

Have a nice day.


  1. Rekhanadh
  2. swetha
  3. Yamuna
      • Nikhil Sonawane
  4. Sanjana sanz
      • Anil
  5. priya
  6. Thejdeep G
  7. Manali
  8. Rajiv kumar
      • Rajiv kumar
        • Rajiv kumar
        • user
  9. Raghu Nandan
  10. Mukesh

Leave a Reply