Handle Multiple Windows in Selenium

Price: INR 1,299.00
Was: INR 1,799.00

In this tutorial you will see, How can you Handle Multiple Windows in Selenium. There are many websites, Which displays or open new window when you click on any link or Button. In Such case, Selenium focuses shifts on new Windows and start work on that window.

So it is important to switch to the specific window recognizing its Title, Element, Content etc.

 

To handle multiple windows we need to switch between windows. Selenium WebDriver assigns an alphanumeric id to each window as soon as the WebDriver object is instantiated. This unique alphanumeric id is called window handle. Selenium uses this unique id to switch control among several windows. In simple terms, each unique window has a unique ID, so that Selenium can differentiate when it is switching controls from one window to the other.

 

Window Handle in Selenium

Selenium provides 2 methods getWindowHandle()  and getWindowHandles() to deal with the multiple browser windows.

getWindowHandle() – This method returns the current browser window handle id that the web-driver is currently holding.

getWindowHandles() – This method returns set of browser window handle ids that are invoked/opened by the web-driver.

And we use switchTo().window(window_handle_id) to switch to different browser windows of the web-driver.

 

Video Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

 

 

Let’s take an example Naukri.com, we can see when we click on any tab on the options present in the menu this will open in new window or tab. So we will design the Test case for this.

Steps –

  1. Open Naukri.com

  2. Verify Page Tittle.

  3. Click on the Recruiters link.

  4. Verify the page title.

  5. Verify any present web Element.

  6. Close the recruiters’ tab.

  7. Verify the currently open window.

 

Let’s see how can we prepare the test script for the above scenario.

So this is all how We can manage the multiple windows. It’s important to understand the concept, We can do this in other ways as well. It depends on Testers technical skills.

Please note, If you are executing the same Test then please don’t forget to close the ad window pop-up on Naukri.com manually. Sometimes this site fire the Ad Pop-up window, which is been not handled in this script. You will learn about to Handle the Pop-up in coming tutorials.

So this is the way how we can handle the multiple windows, multiple tabs and windows pop-ups in selenium. Feel free to write us if you have any query in the above tutorial.

0 Comment

Leave a Reply