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

 

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.

 

 

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.

 

 

16 Comments

  1. priya
  2. Thejdeep G
  3. Manali
  4. Rajiv kumar
      • Rajiv kumar
        • Rajiv kumar
  5. Raghu Nandan
  6. Mukesh

Leave a Reply