Multiple Windows Handling in Selenium Webdriver

Multiple Windows Handling in Selenium Webdriver

There are many web applications which have pop up windows or child windows or multiple windows. So while Testing if we use Manual Testing then we can do the testing by operating all the windows separately. But if we want to automate this kind of scenario then we need to do multiple windows handling in selenium webdriver.

Suppose there is a scenario where we have to manage multiple windows and need to navigate in all the windows for example: Open spicejet.com >> fill mandatory fields >> click on Find flights button >> now click on Currency Converter link which is available on the page >> then enter the values in the pop up >> close the pop up and select any value which is going to be fit.

• To handle the pop up or child window, we need to navigate from the main window to the pop up window by using the below command, we need to enter the child window or pop up window name in place of “window name”:

Syntax: driver.switchto().window(“window name”);

• To navigate back from pop up to main window again, we have to use the same command we need to enter the main window name in place of “window name”:

Syntax: driver.switchto().window(“window name”);

Get Window Handle

This type of command is to take the window name from any child window or pop window or main window where the webdriver is having the focus.
The written type of get window handle is string.
Syntax: string str = driver.getwindowhandle();
              driver.switchto().window( str );

Note:
To handle the frame, we need to navigate from the main window to the frame where we need to pass the frame id or frame name.
Syntax: driver.switchto().frame(“frame id / frame name”);

 

Click here to Read How to Handle JavaScript Alert Messages in Selenium Webdriver 

Click here to Read How to create Automation Script in Selenium Webdriver 

3 Thoughts on Multiple Windows Handling in Selenium Webdriver

Leave a Comment