What are GetWindowHandle and GetWindowHandles in Selenium? | Selenium Basics

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys welcome to my channel software testing by GT as a part of this video I'm going to talk about get window handle and get window handles are the two methods that we have in selenium get window handle and get window handles are often used when we have more than one window or whenever we have whenever we have to play with Windows right let me give you example [Music] practically now if you guys are able to see my screen you will see that as of now I'm dealing with a single window right but what will happen if I have more than one window right one is one window this and one is another window this right how will I move my control from parent window to the child window right so see guys in selenium it is possible or in any web- based application it is possible that many times tester will have to deal with multiple windows like this now the question comes how to deal with such application Whenever there are so many windows together right so for that reason we have get window handle and get window handles the two famous methods that we have in serium let me write it and show it to you guys get window handle will always give you the parent ID of your browser it will always give you the parent ID of your browser or it will give you the browser ID of that browser which has the control I'll explain you the meaning please don't worry which has the control control what does it mean guys the ultimate goal of my get window handle is to give me the browser ID wherever my control is present as of now guys let me tell you if you're playing with multiple windows or multiple windows and child uh popups right all windows and child popup or all multiple windows will have their browser ID but get window handle is not going to tell you the browser ID of all the tabs that are open no no get window handle will only give you the browser ID of that particular browser that has the control let me show you practically probably then you will understand better that's why all the serum classes has to be practically otherwise chances of understanding will definitely be very less what I'm going to do now I'm going to create a class give the class name as get window class and this class will have a main method or you can also have at the rate of test annotations so here we are going to launch Chrome driver driver is equals to new Chrome driver and let's import it you know what this line will do I need not tell you I believe it will always launch the in browser then it will take you to a website called as whatever the website that you will mention here so I have passed www. google.com take example I also wish to maximize my browser driver. manage. window. maximize with the help of this driver I want to play with my get window handle this is the method I'm talking get window handle handle right guys get window handle return type is a string why because I have said you the reason because it always give you the browser ID guys always IDs will be browser ID will be alpha numeric and you know that out of all the data types that we have in Java only string is one of the data type that we have in Java that stores alpha numeric value so I'm going to pass here string and I'm going to give my reference variable as parent ID I'm done I'm just going to print my parent ID here so whatever the parent ID have received here I'm just going to print it and I'm going to run it once this is done you can go back to your eclipse and this is the alpha numeric value guys this is a parent ID of which browser the one that you have run so as of now you ran this particular browser as of now right which is Chrome and you opened a website called as google.com and what is the browser ID the browser ID is this of this particular URL that you launched just now on Chrome driver if you guys are thinking that in case if I run it again if you guys are thinking that ID will be same so let me tell you no guys every time you run a program the browser ID is going to be different each and every time you run the program the browser ID is going to be different different different and different not always the browser ID can be SE that's what get window handle is all about right so if someone will ask you tomorrow what exactly is get window handle guys get window handle will always give you the parent ID of your running browser right or it will give you the idea of that particular browser that has the control guys as of now the browser that you are running has a control right you have not yet mov the control to the any other browser or any other tab right now let me show you what get window handles will do this is about get window handle what about get window handles guys we also have one more method called as get window handles it gives you the browser ID or browser ID is of your parent and child browser so get window handles will give you the browser ID of your parent and child browser that means if you have a browser open and you have a tab open here one and two tabs right so this is going to be your parent browser or parent Tab and this is going to be your child tab let me show you practically don't worry watch out what I'm going to do now I'm going to show you this I'm on this particular website called google.com and I'm doing the right click on Gmail and opening one more tab I'm pretty sure you have understood now who is parent tab here and who is child tab here guys just like in normal life parent will come first and child will come later here also whichever tab has come first is a parent tab or your parent browser and whichever have come next is called as a child tab so parent tab will give you parent ID and child tab will give you Child ID but now the question also comes is having the child tab always mandatory no guys having child T always is not mandatory just like in normal human life having child always is not mandatory for any parent take example just like that if you launch any browser like or if you launch any website called as google.com whether child tab will come or not we don't know it can come if you perform some action right let me show you practically guys as of now you guys can see that I am launching a website called as google.com that's all and if I do now get window handle and get window handles what I will get let me show you guys I'm going to write a statement here called as driver. get window handles and uh the return type of get window handles is a set of string oh my God what is this guys get window handles return type is a set of string that means just because as I have said you it has a capacity to give you multiple IDs because some browser will have multiple tabs open parent and child opens right that's why the return type is a set of string where set is a interface right I'll show you please don't worry give a reference variable so I'm giving the reference variable able as parent child equals to and let me import this set coming from java utin not from Z star please remember you can H over set to check what exactly is this you can see it is purple ey purple ey always indicates interface please remember guys now just like how here you have printed your parent ID here I'm going to print my parent and child ID and I'm going to run the program once again after running the program you can see here this is this line is a result of my this which is called which is a result of my get window handle and this line is a result of my get window handles where I'm supposed to get B both parent ID as well as Child ID so the first one that ID that you get is always a parent ID but since there is no Child ID present here because there is no child browser present we did not get any child ID so guys this is a result of your get window handle and this is a result of your get window handles now what I'm going to do guys I'm going to take you to a website called called as no.com after taking to you uh to a website called as no.com what I'm going to do I'm going to click on this continue with Google after clicking on this continue with Google Now you can see I have two windows one is this window hope you guys are able to see and one window is this right I got two windows right I got two windows now one is behind one is in front I hope I not tell you now that out of this two window who is parent and who is child if you want I can tell you again whoever have come first is a parent and whoever have come now is a child right so if you look at this website called as register or.com first is a parent browser whoever have come next is the child browser so let me show you this particular part so what I'm going to do I'm going to launch this particular URL after launching this particular URL I'm going to maximize the browser after launching this I'm going to click on Google so let me see how I can locate this inspect Google so I got got Google text here so I'm going to write a xath guys please notice there is a way to write a xath whenever we have the text available with us and the way to write a xath here is double for slash your tag name the tag name is Spam dot equals to the value I'm going to show you once again please don't worry I'm going to inspect my Google after inspecting your Google you guys can see what I have done double forward slash why double forward slash this is how I'm locating my element with the help of a x paath what kind of X paath is this guys X paaths are of two types one is relative X path one is absolute xath this is called as relative xath because double forward slash has come right and what is pan this is a tag name dot represent I'm going to deal with the text message equals to Google Once after doing this you can see total count I got is one of one if I have one of one that means I can utilize this for clicking purpose clicking on Google right watch out so what I'm going to do now I have launched this particular website after launching to this website I have maximized my browser after this driver do find element how by xath what is your xath this is your xath wonderful what is return type of find element it is web element interface please remember guys the return type of a find element is a web element so web element A1 is equals to in this fashion you can write it hover over web element import it you can hover over web element again to check that web element again is a purple I I always indicates interface now with the help of this A1 you can perform function here what function you want to perform here what action on that Google link you want to click so just type click so let me show you what exactly I'm trying to do here I'm opening this no.com clicking on Google after clicking on Google I got my parent I got my child and now I'm going to do get window handle and get window handles guys now you can see this particular line is a result of my my get window handle as you know get window handle will always give you the parent ID doesn't matter Childs are present or not present doesn't matter children are present or not present because I have showed you that get window handle will always give you the parent ID and as you know you have only one parent here since only one application you are launching so it is the result of your get window handle what is the result of a get window handles parent ID and the Child ID since guys after running uh the particular application and clicking on Google I got one child so this is my parent ID and this is my child ID and this is my parent ID this line is result of my get window handle and this line is result of my get window handles so this is uh this is what is the main difference between get window handle and get window handles before I conclude this video let me take you to the website again want to show you something see guys this is my parent window and this is my child window get window handle will give give me the ID of this particular browser get window handles will give me id of my parent also and my child also right guys it doesn't matter how many child browsers that you have it doesn't matter get window handle is not going to care about it because get window handle will always give you the parent ID only but get window handles will take care of the parent IDs as well as Child ID why I'm teaching you this what is the main purpose of this particular topic you will understand slowly in your upcoming chapter make sure that you guys are watching my selenium playlist in which I have uploaded all the videos one by one only if you watch that in a particular fashion you will understand that what exactly is happening see you in the another video guys till then take care
Info
Channel: SoftwaretestingbyMKT
Views: 3,462
Rating: undefined out of 5
Keywords: softwaretestingbymkt, mkt, manish kumar tiwari, software testing by mkt, Best YouTube channel for software testing, getWindowHandle(), getWindowHandles(), switchTo(), Window(), Selenium WebDriver Commands, java, java programs, sdet, seleniumtutorial, automationtester, automationtesting, javaprogramming, javatutorial, javaprogram, javaquestions, testautomation, seleniumtutorialforbeginners, seleniumwebdriver, javaselenium, chromedriver, webdriver, what is getwindowhandle and getwindowhandles in selenium?, jira
Id: VxaGUV01y0Q
Channel Id: undefined
Length: 12min 41sec (761 seconds)
Published: Tue Feb 20 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.