top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

Window Handling In Selenium

A window in any browser is the main web page on which the user lands after hitting a URL. Such a window in Selenium is referred to as the Parent Window or Main Window. It opens when the selenium web driver session is created and has all the focus of the WebDriver.


When you open any website, the main page where you will perform any operation is the Parent Window. This is the same webpage that will open when the Selenium automation script is executed. Now, all the other windows that open inside your main window are termed as Child Windows.



Here, we are going to see how to do window handling in selenium.

In the above Juice Shop website, Once you placed an order .We can track and print order details.



When you click on “Print Order” ,Child window will be open .In this scenario, we have to switch back to parent window and logout from the application.

                                          



Selenium WebDriver provides various methods for handling of windows. Few of them are:

  • getWindowHandle( ): When a website opens, we need to handle the main window i.e the parent window using driver.getWindowHandle( ); method. With this method, we get a unique ID of the current window which will identify it within this driver instance. This method will return the value of the String type.

  • getWindowHandles( ): To handle all opened windows which are the child windows by web driver, we use driver.getWindowHandles( ); method. The windows store in a Set of String type and here we can see the transition from one window to another window in a web application. Its return type is Set <String>.

  • switchto(): Using this method we perform switch operation within windows.

  • action: This method helps in performing certain actions on the windows.


Thanks, Keep Learning!!!

62 views0 comments

Recent Posts

See All

コメント

5つ星のうち0と評価されています。
まだ評価がありません

評価を追加
bottom of page