Right so so far uh we have learned how to locate web elements in the different way approaches and different ways uh using the basic attributes like ID name uh and then uh CSS and xath and so on and also we have seen different types of xath and how to create a relative xpaths and so on so from today we are going to start how we can interact with the different type of web elements so what is a web element web element is an element which is present on the web page it can be input box
it can be checkbox or radio button drop down anything whatever you can see on the web page which is called as a web element in the selenium prospective you can call it as a web element and in some automation tools we can call them as a web objects web objects or web element anything is same but in selenium normally we can call them as a web elements everything is a web element okay so first of all let's see how we can handle this web elements so before handling handling is nothing but first we need to
locate a web element and then we will perform certain type of an action on the Web element every web element is having different type of actions we can perform so before going to learn how to handle different type of web elment there are few commands are there in selenium and we have to learn those commands before interacting with the web elements okay so there are are five types of uh commands we can say commands or web driver methods we can say methods also so these are all predefined methods which are already there in web driver
and we should know how we can use those methods so let me list out those methods so get methods conditional methods browser methods navigational methods and then weight methods so these are the five different categories of methods which are very commonly used in our Automation and these are not related to web elements actually but uh yeah so we can use these conditional methods on web elements also but there are some more other commands also there these are some basic commands which we have to use on day-to-day basis in our automation okay so first we'll start
with uh these commands first get methods so there are some methods and all these methods we can access from the driver web driver object so as soon as You create web driver driver equal to Chrome driver by using the driver object we can access all these methods okay so first let us start with uh get commands there are uh five to six commands are there under get commands we'll see what are those commands and then I'll show you practically how we can use them so get methods we can access these commands through web driver instance
and uh why we call calling them as get method we can simply say all these command or methods starting from get keyword like get get title get current URL get pay Source get window handle get window handles so these are the six commands or six methods are there in web driver and what is the use of these commands so get is one method when I pass URL as a parameter so this will opens the URL on the browser so this we already seen many times so as if you want to launch any browser or open
the URL application so this the command or method we have to use and get title sometimes we need to perform some validations on the titles of the web page so if you want to get the actual title of the web page and that we will uh we will compare with our expected title so in those cases we can get The title of the current web page using get title method so this will also Returns the title of the page in the string format same thing get current URL so while navigating between multiple Pages if you
want to validate the URL is correct or not so you can capture the URL of the web page that you can compare with your expected URL so for that we use get current URL so this method will return URL of the web page and get page source so this will return return source code of the page so whenever you browsing some page you will get some response from the server actually that response is uh we cannot understandable format so that is a combination of HTML JavaScript some CSS the combined code will be there so if
you want to get that page source so we can use this command it will return the source code of the web page and for example let's say you can take any web page so I'm just browsing one page but as a user I'm able to see this Google form but the server is responded like this you can see view pay Source if I use this this is your view pay source so if you want to capture this information from the pay Source you can use get Pay Source command the next one get window handle and
get window handles so the get window handle method will returns an ID of the single browser window means so normally elements are having some attribute suppose if you inspect this element you can see attributes of the web elements in the Dom itself here you can see but every browser window suppose I'm using this google.com Okay and this browser is having some kind of an ID that will be generated at the run time and that ID is also more Dynamic every time you won't get a same ID okay and by using that window ID we will
do certain type of operations like switching between multiple browser windows or if you want to perform actions on multiple browser windows if you want to achieve this we need this window ID so that window ID we cannot find anywhere even in the Dom also it will not be able to generate even in the Dom also we cannot see that only at the time of browsing the web page or at the time of opening the web page that ID will be created by the browser itself at the run time and that ID will not be same
if open google.com page now the ID will be different next time it will be different every time when You open the browse or when you refreshing the browser or when you open the application every time the ID dynamically will change so if you want to capture that ID we use this command get window handed and sometimes if you're are opening multiple browser windows let us say uh here okay I'll try to open some application this let's say have open one application here so this window is having one ID by default and when you're trying to
navigate some other window suppose I'm clicking some link and it is opening another tab or another browser window now currently I have a two browser windows now I want to capture the IDS of all the browser windows currently open So currently two browser windows open so I want to get these two IDs dynamically in that case we can use this get window handles okay so get window handle return ID of single browser window whereas get window handles returns IDs of multiple browser window so I will discuss them in detail with an example Later so these
are the basic get commands or we can say get method okay so that ID contains some combination of numbers and characters it is ID is basically in the form of string it will return okay get window handle get window hand is return IDs in the form of string so we will discuss that later in detail so this is not the right time so I'm just listed out all the methods which are comes under get methods get get title get current URL get P Source get window handle get window handles all right so now we'll see
practical examples and how and where we can use these commands let's go to eclipse and uh let's create it is just give only ID and we can also call it as a handle the value of the handle for every browser window which every browser window is having that ID that will be generated at the Run okay so now now let's create a new package and say Day 26 inside this I'm creating new class I call it as a get methods okay so now let us try to use this commands uh By taking some application so
I'm taking this orange HRM application so I'm trying to launch a new web page I can say web driver we have to first create web driver uh can you see my screen guys web driver driver equal to new Chrome driver right so control shift O So packages are imported now I'll try to launch an application driver dot get off so this is a URL of application so I just open this okay this is the URL of application just copy this URL and paste it over there now so as soon as you launch my web page
okay so the first command is what get so what is a get command is doing get is a taking one URL of the application as a parameter and and this will launch your application on the browser and who will launch the browser our driver Constructor so as soon as you created an object for the Chrome driver this will launch your browser and once it is launched we are launching the URL or we are opening this application URL on the same browser and will it return return anything for us get method so get method doesn't return
return anything it Is just saying void get method will not return return anything but it will take parameter and do per some action so get method will be used to launch the application URL so this is the first command all right now the next one so once you launch your application I want to find title of the web page so this web every web page is having some unique title normally where we can see the title if you inspect this a particular web page on the header tag you can see one new tag called title
here so this is the title orange HRM this is a title of the web page okay and this title will uh will be different from one page to another page so if you want to capture this title then we can use get title method so I can say driver dot get title so you don't need to remember all these methods it's very simple if you just simply say driver dot just type get keyword it will show you all get related methods okay so I'm trying to use get title so what is the written type of
this this written type of the method is string so get title method will return return the title in the form of string so you can store That value in a variable then you can use it for comparison or if you want to directly print you can still print it so I'm directly printing by using print statement so driver dot get tip so this will return the title of the current web page and that I'm going to print in the console window so this is second command get title so get title Returns the title of the
web page okay now you can see this is the title of the web page right so similarly we have another command called get current URL so this will return the URL of the current web page so that is exactly equal to this one so whatever URL we open so the same URL suppose if you're navigating between multiple Pages then you will get a different type of URLs okay so get current URL I say driver dot get current URL and this will also return URL in the form of string so that I can print directly driver.
get current URL and if you still want to store in a variable you can store in the variable and then you can compare with your expected URL as part of validation this is get current URL yes so we still not done anything on the web page just we are capturing the required information so now you can see this is a URL of the web page so it is exactly same as this one as in the beginning whatever URL we open same URL it will be written get current URL so next one get page source and
this will return page Source but what is the use of this paid source so what is the necessity of this normally PID Source means if I right click and view pay Source it will show you the pay Source this is actually written by the server but we cannot understood this particular language right so the browser will convert this into UI format so in the UI format we can see everything but if you page is in in this particular format we cannot understood right so if you want to capture the source page pay Source we can
use this command but what is the use of this page Source sometimes if you do if you want to do some validation on this page Source let's say uh some text is present on the page Source or some element is present in this page source or not and if you want to check first we need to capture the pay Source Okay and then we will check or we'll do some validation on the pay Source okay but this is not that much important we don't do uh source code validation most of the times but they have
given some command like this this is pay Source let's try to execute this driver. get page source and this will return the entire page source so in the string format so that try to print it driver. getp Source okay now you can see this the console window we got entire the pay source so this this is all pay source which is written from the application so from here it is started from HTML is the root node right so everything it is so which contains HTML JavaScript combination of code because normally web pages are designed by
using HTML and then combination with the JavaScript so this is get page source and we never use this command most of the time is not much important and the next is get window handle get window handle so these are the most important two commands most of the times we use this in our automation so for now just understand what exactly This will return but once it is return window ID with that window ID we will perform some further operations okay I'll show you that also first we'll see how we can use this get window handle
so this will return the ID of the single browser window single browser window Okay so so let me just a second yeah okay so just commenting this Bas source for now right so now we'll see get window handle so we already launched this particular page okay so now I want to capture the ID of this current web page can say driver. get window handle so this will return the string type of data so I can just print it okay let me store this so basically get window handle will return the string type of output so
the ID will be present in the form of string so I'm taking one string variable string window ID and after that I'm trying to print window ID okay so I can also put some small text window ID okay now as I said this window ID is not a constant value so this will keeps changing dynamically at the run time because this ID will be created by the browser at the run time so if you look at here I'm launching my browser opening the URL so this is the window ID which is got returned see this
this is the window ID okay now next time again I will run one more time now this time you can see it will return another type of window ID because this will not be the same every time yes now this time it is written on another type of window ID okay this is in string format see now you can't compare these two because both are totally different type of IDs which are generated so whenever you are launching a new browser window as soon as you launch a new browser window the ID keeps changing this is
dynamic okay so this is a get window handle get window handle will return the ID of the browser window single browser window now sometimes if I open multiple browser windows then I can capture the IDS of multiple browser windows at the same time I'll tell you what is the use of this command first lesson how we can use it okay get window handles it will also Returns the IDS of multiple browser window so whenever you want to use this command uh if you have at one if you have one single browser window anyway it will
return single ID but if you have a multiple Browser windows are open then it will return IDs of all browser windows okay so for example uh what I will do is uh this is the web page we are currently opening right so I will comment this window ID also right so this is a web page currently opening so this is having one ID so after opening this window ID so what I will do is I will try to click on this particular Link in the bottom orange HRM ink so once you click on this link
it will open another browser window so now I have a two browser windows and once you open the second browser window then I will use get window handles commands so that we will know exactly whether it is returning IDs of both the browser windows or not okay so what I will do is this page we already launched at the beginning now I will perform click action on this element R HRM Inc so that it will open another browser window so let's inspect this element and uh yeah you can take this as a partial link text
or you can use as an xot anything is fine right so I'm taking this link text and try to click on this element so driver dot find element by dot link text and this is a link text Dot Click so this should be do click okay so once you click on this element then what happens it will open another browser window so this action or this will open new browser window so that is the reason we perform click action okay so once it is open new browser window now I'm going to use get window handles
driver dot get window handles yeah so now what is the return type of get window handles so get window handle will return single browser browser window ID so it is a string get window handles will return multiple browser windows in the form of strings every window ID is a string but this time it is rning multiple right not only single multiple window IDs so the return return type of this method is set set collection will be return returned and what is the set contains all are strings because all IDs we are going to store in
the set collection so here I'm taking one variable called window IDs now the type of variable is set of string set of string now this set collection we can import from java. so these are the collections already used in selenium okay so the get window handles return set of string why it is a string Here because all IDs are in string format okay why it is set why can't we can use a list collection here can anyone tell me the reason why they have used set instead of list collection yes so window IDs are unique
so all window IDs each wind each browser window is having different type of ID okay they will not be the same so set collection doesn't allow the duplicates right but if it is a list collection it is allowing the duplicates but there is no possibility to have a duplicate IDs so that is the reason they have created set collection the window handles return set collection okay now if you want to print So currently we open two browser windows so it is returning IDs of two browser windows now this variable contains the two browser windows now
I want to print them how we can how we can get those browser windows from the set collection from the set collection how we can extract window IDs okay let's try to print it directly I just put this variable inside this Sprint just observe yeah it is giving an error so let's see what is an error It is giving so whenever you get an error or exception just try to read it so that you will know some information yes no such element exception comes and when you will get the No Such element exception in which
scenario you will get the No Such element exception whenever it is unable to locate element then you will get an exception and why it is unable to get unable to locate element what element it is this is the element orang HRM link element it is unable to locate it is not saying element not found element it is saying no such element exceptions so whenever you say no such element exception most of the times it is because of synchronization problem because the page is loading slowly but by the time it is trying to find this element
but if this element is not still available on the web page then it is throwing unable to locate an element okay then what is the solution for this for now just add one weight method you can add weight method Anywhere But as soon as you launch my web page here I'm adding This Thread do sleep and I can put 5,000 Milliseconds so this will also we will discuss as part of uh weight commands later all right so now if you execute this you can see the actual operation so first it should launch my browser then
it should click on the link right so after 5 Seconds yeah it is clicked on the link then it is open another browser window now I have a two browser windows first one and second one now if you look at here it is written the entire set collection so the first value is this one the ID of the first browser window this is the ID of the second browser window but it is wring in the form of set but if you still want to get individual values how we can get individual values either you can
convert this into ARR list and use get method or you can use a looping statement you can use for each Loop and then you can get individual values okay that's the process okay that we'll see later so this is about this is how we can capture the IDS of multiple browser Windows okay so for now just remember only this much and what we can do with the window IDs what is the use of this window IDs so sometimes what happens is if you have only one single browser window like this If you want to close
this automatically then how we can close through automation I want to close this my browser window you can simply use driver. close command or you can use driver. git command so they are all comes under browser methods actually there are two commands close and quitter suppose when I'm using close command and when I'm using quit command what is a major difference here is close command will able to close only one single browser window at a time suppose I have one browser window like this I can close this directly because I have only one browser window
and suppose you have multiple browser windows suppose I have a two browser windows windows or you may have n number of browser windows now I want to close all of them at one shot or I want to close all of them at a time then you can go with the quit command so quit command will close all the browser windows at a time whereas close command will close only one browser window at a time okay that's a major difference but now my question is let us say I have multiple browser windows like this multiple and
how many are there now 1 2 3 4 5 in this five browser windows I want To close some of the browser windows based on my choice let's say first and second I want to close or second and five I want to close or three and one one and three I want to close so based upon the choice I want to close that particular browser window so how it is possible this is very popular interview question remember this if you if you are using close command and only one browser window window will be closed whichever
browser window is got focused by the driver that will close when I use quit command it will close all the browser windows at a time now based on my choice I want to close specific browser window then what I should do is first you need to capture the IDS of every browser window and then you have to Loop it each and every browser window you have to capture based on the browser window ID we can get the title and then we will compare the title with your expected title if both are matching then we will
close the particular browser window so that's the process but before that before using this window IDs we should know how to switch between multiple browser windows so currently uh normally what happens is I open this web page this is my first web page I open now where is my current driver is focused on this particular browser window as soon as you click on this link it is open another browser window now where is our driver focused first page or second page what is your guess so as soon as open as soon as I click on
this link it open another browser window now I have two browser windows where is our driver focused so most of the times we think driver is will focus on the second web page but no driver is still focused on the first page it cannot directly switch to one page to another page until unless we do it okay so as soon as you click on this link even though it is still even though it is opening another web page like this but still driver is focused on first browser window only okay but now I want to
perform some action on the second browser window so here I can do some actions username password everything I can do but as soon as you open the second browser window and here I want to perform some action let's say I want to click on some link here I want to verify something in the second page but driver is still focused on the first page so how we can get the driver switch to One Browser window to Second browser window so this is possible using switching commands Okay so in the coming sessions I will introduce those
commands how we can switch between One browser to another browser how we can switch our driver to One browser to another browser so once it is Switched how we can switch to switch One browser window or another browser window what is the source what is the parameter we requir is window ID so if you know the window ID by using that window ID we can switch to One browser window to another browser window okay suppose if you know this window ID this browser window ID I can easily switch from first browsers to Second browser window
then I can perform the action so where exactly in that particular scenario we will use these two methods get window handle get window handles but I will show you that scenario later just I'm giving you some basic uh understanding so where exactly we use this get window handle get window handles but before learning these two methods we have to know how to switch between multiple browser windows we have a separate kind of switching commands are there so once you Understand the switching commands then again we will come back and discuss about get window hand get
window handles probably in the next session I will show you that example okay so these are the two methods are available for now just remember get window handle will return the ID of single browser window get window handles will return the IDS of multiple browser windows okay so that is enough so get window handle will return string get window handles returns string of set collection string of set collection even this is also keeps changing same ID you will not get every time okay so these are all comes under get methods all methods are accessible from
the web driver instance understood everyone so these are the get meths so far everyone is clear please confirm in the chat box now I'll move to the next one very simple very easy I can take any web page and you can explore these methods you can apply these methods on any type of web page randomly you can take some web page from the internet you can try these commands just do one round of practice okay so now let us move on to the next one conditional methods they are very very important conditional Methods okay so
conditional methods we can access from the web element not from the driver okay conditional methods we can apply on the particular web elements conditional methods we can apply on particular web elements and get methods will not work on the web web elements these get methods will work on the web pages okay so get get title current URL Source handle these are all related to web page but not web element remember the difference okay all get methods will work on the web page level not at the element level we are not going to interact with any
element here we are just used this methods only by launching the browser window that's it okay whereas conditional methods we can access or we can apply these methods on the web elements okay we need some web element on that web element we can use this conditional method so there are three methods are there and these three methods will return true or false Boolean value will be return is displayed is enabled is selected these are the three methods are there is displayed is enabled is selected so get text is another method which we can also use
along with the along with the web element suppose If there is an element if you want to capture the text of that web element you can use get text so get text method will not comes under under this category why because these get methods will access only from the directly from the page but get text method will related to web element okay get text method we can access only from the web element not from the web page not from the driver but these get methods we can access only from the driver instance whereas get text
method we can access from the web element I will show you that also but that is not comes under this particular cat right so get uh here conditional methods so conditional methods we can use on top of web element will perform EAS displayed means what it will check that element is displayed or not it can be any type of element it can be image or input box link button anything that is displayed on the page or not that we can verify by using e displayed and is enabled Sometimes some elements will be disabled an enable
State and we can check that element is still enabled or not and that element is in working condition or not we can check by using ease enabled method and this is also we can use For any type of web element ease selected and this method especially we can use for uh radio buttons and checkboxes means what suppose the radio button is there you already selected and when I use this method it will check the radio button is already selected or not if it is already selected returns true if it is not selected return false same
thing for checkboxes also I have multiple checkboxes I selected some of the checkboxes but some of the check boxes are unchecked so this command will check whether the checkbox is selected or not if it selected returns true if it is not selected return false okay so these are the conditional methods we can access from the web element not from the driver okay remember and these conditional commands will return a Boolean value which is true or false all right so now we'll see the practically how we can use this commands let's create another example new L
additional methods Okay so this time I'm trying to open some other web page so web driver driver equal to new Chrome driver and then I'm launching my packages and this is the page I'm launching this time so I can just look at this n Ecommerce ation page okay now we can see some small registration form is there and there different type of web elements some radio buttons are there input boxes drop downs and some checkbox also here right some elements are there okay so we'll try to use this conditional commands on this particular web page
also uh as soon as you launch my page like this small window I want to maximize it so how can we maximize the page driver dot manage dot window do maximize so this command will maximize the web page okay now the first command is what is displayed is displayed so this particular command we check the element is displayed or not okay for example let's say I want to verify this logo is displayed or not this logo is present right I want to verify this logo is displayed or not so what I can do first we
will capture this as a web element now inspect this element And uh you can create your own xath or you can directly go to selector hub from the selector Hub you can get the expath of the image okay this is a IMG so this xath so I'm getting this xath and capture that element driver Dot find element by dot X paath okay and this is the web element now I'm storing into a variable now tell me what is the type of this variable type of this variable is what type of the variable why it is
Boolean did I use display method on this web element did I use any EAS displayed method no right but why you are saying Boolean so this will return always web element find element method will always return a web element so this logo is what is a web element variable okay it is a web element variable we have to import this right so once you get this web element then we can apply the conditional methods okay now I want to check this logo present or not simply what you can say logo dot is displayed is displayed
and this will return a Boolean value true or false that I can print system do do do print Ln logo dot is displayed okay so here I will put something I can say display status of Logo like this so before before using this conditional method we first we need to capture the web element so we captured this entire web element in a variable and then by using that variable I call this e displayed method so from where we are accessing this method from the web element class not from the driver okay now execute okay now
open maximized now can go back and see yeah display status of the logo is true it is displayed now I will write something you guys can tell me whether it is correct or wrong I'll write driver. find element by. XPath and also I'm using same thing same X paath okay dot is displayed and here I'm taking a boan variable called status and now here I'm printing display status status okay now tell me is this statement correct or wrong correct or wrong can we write like this yes why because we are identifying the the element here
once it is identified instead of storing that element in another variable I'm directly Using is displayed okay now final method is what here is displayed so what this will return a Boolean value so this variable should be Boolean and that I'm going to print but in the first case what you have done first we capture the element in a variable and then I call this e displayed with the variable and then I printed directly and you can also write like this anything is correct I hope this is clear to everyone it's very basic on context
okay now easy displayed method you can apply for any type of web element so you can also check this input box is present or not this label register is present or not okay and anything you can check on this web page and the E display method is applicable for all kinds of elements now the next method is enabled is enabled okay and this method especially used for input boxes most of the times we'll use it for input boxes and uh drop downs radio buttons and checkboxes okay because images we don't do any actions right so
even image is enabled or not nothing to do with that right but suppose input box is enabled then only we can pass some text okay suppose here I Want to search for something if you want to type something that input box should be enabled State okay and if it is disabled State I cannot pass any value into it that's called disable status enable and disable enable means it is allowing us to provide some data disable means it is not allowing to provide some data sometimes you can see disabled fields in our application so in those
cases you cannot part you can you cannot pass any value into it that's called disabled status so most of the times before passing the value in it we will can check or we can check this input box is enabled or not that's a conditional statement okay so let me check some element is enabled or not in this particular web page so let me check this one search store is enabl or not or you can check the first name is enable or not let me inspect this element first name I'm taking and uh can go back
to the xath select our Hub okay this is the xath which is given now I'm using this XPath and this also is enabled also will be used on top of web element so I can say driver. find element by. X paath okay now if you want to store this in another element you can store Another variable or else you can directly use that method dot is enabled and what this will return what is the type of this variable what is the type of this variable it should be volan okay so once you capture the web
element on top of web element we apply this method e is enabled so this will check enabl or not if it is enabled returns true if it is not enabled then returns false and before passing the value in the input box we can cross check whether that element is enabled state or not if it is enabled State then we can continue if it is not enabled then would don't contate so in as a part of validation you can use this method especially the conditional methods we use as part of validations so here I'm just printing
enable status okay that's it and suppose if you apply these methods for any disabled Fields then it will return return false yes I already told you right so this method you can use it for any type of elements any type of element but there is no use radio buttons checkboxes that is fine but what is the use of uh Using that method on the logo some static test no use right so this will return true enable status is true okay so when it is a valid you can use it for anything but the problem is
suppose if we are using enable or disable can we check that logo is enable or not do it make any sense nothing right so for example label enable or not is it make any sense nothing right but where we can use exactly is suppose if you want to perform some action on that element suppose radio buttons so before performing an action you can check whether it is enabled or not so that is a valid it makes sense same thing for input boxes also we can use it because we can do some kind of operation here
enable or not you can check same thing drop downs you can check check boxes also you can check okay but it doesn't make any sense if I use for labels or images nothing to do with this enable or not even buttons also you can check whether button is clickable or not enabled or not if it is enabled then only we can click if it is enabl if it is not enabled we cannot click okay other than the static kind of elements all other type of elements We can apply static elements in the sense there is
no functionality associated with it is just display on the web page but there is no action for those elements they are called Static elements okay apart from those type of elements you can apply these methods for any type of web elements yes that is also a true scenario sometimes submit button is not enabled so until unless you provided all the fields so then what you need to do first you need to provide the fields provide some data and after that you can check the submit button is enabl not so before providing the data should be
disabled after providing the data should be enabled both the scenarios we need to validate as part of automation okay so that is also part of the validation so before providing the data it should be in disabled State that's is our expected after providing the data it should be enabled that is also our expected okay suppose as part of your requirement as part of your requirement after providing the data also the submit button is not enabling then it is a bug okay after providing data so the submit button is not enabled that is a bug so
before providing it should be it Should be disabled after providing it should be enabled that's our expected so we need to also do the negative testing like that okay so these are the enabled method so EAS displayed method we'll check the element is displayed or not enable method will check the element is enabl or not in other words we can say the element is operational or not okay element is displayed or not element is operational or not can say can we can check display status of the element is enabled we can check enable or disable
status of the element especially this is operational element not static element okay now can we first use get for particular page followed conditional method so you can use anywhere okay you can use conditional method first then you can use get methods next voice Versa that is up to your test case based on the test case you have to follow so in the test case you have a steps right 1 2 3 4 the same order we have to automate the test case we need to consider the steps of the test case case not the commands
Okay according to the steps whichever command is applicable there or appropriate we will use that command so you Need to follow the test case while automating the test case okay now the next method is is selected and this method we can use we can use to check the element element is selected or not selection so selection means what it is applicable for checkboxes because checkboxes we can select uncheck or we can select or unselect radio buttons also we can select or un select what else we can do yeah radio buttons and checkboxes mostly we will
use is selected method and sometimes drop down also this drop down we can select some value as soon as you selected some value from the drop down we can also use e selected method whether the drop down is already selected value or not we can check by using e selected method so we this but method we can apply for check boxes radio buttons and also drop downs is selected yes now let us try to use it so the next method is select okay so on the same web page so I have a two radio buttons
are here so by default none of them are selected male Reveal by default is selected or not no one is selected okay now if you apply this method EAS selected method and male and female radio buttons what is an output you will get because none of them are selected by default no nothing is selected so when I apply e selected method on male and female on both by default I will get false because they have not selected okay so before applying what I should do is we will capture these two elements radio buttons we have
to capture male and female both I will capture so how to capture it inspect this element you should inspect the the round shape not on the label okay so you need to inspect like this this is the right way to inspect not this one or not this one also you need to exactly point the round symbol now there is an input tag is there even for radio button check boxes input boxes for all of them you can see same tag name called input so this is input tag okay now I can use a locator so
you can see there is a xath is got generated so I'm using this xath you can use any type of Loc a CSS or whatever you want you can use this so I'm Capturing this element I can say driver dot find element by. xath and I'm storing this element in a variable this is a male element I can say malecore Rd male radio button and what is the type of this variable what's the type obviously it is web element everything is a web element okay same way I will also capture female radio button let's inspect
that element yeah this is a another radio button driver dot find element by. X paath and I'm storing this also because I want to perform some further actions on these elements that's the reason I'm storing into the variable and if you don't have any further options directly you can here you can use e selected method okay web element and this is female _ Rd okay so now I have captured both elements now just observe I'm using malecore Rd element dot is selected and I'm printing something here so before selection so before selection I'm trying to
find the selected status of male AO button and also female AO button so what is our expected false because none of them are selected at The beginning both are not selected so obviously we are expecting false okay let's see whether it's is rning false or not before selecting any of the radio buttons okay so I have not selected anything just by default is empty now if you go back and see before selection both are false before selection both are false okay now I want to select one of the radio button okay so here I'm printing
after selecting mail radio button after selecting mail again I will print both okay but how to select if you want to select any radio button simply what you can do take that element dot click just use click method so this will select radio button okay so as of now which one I'm selecting male radio button selecting so this will select male radio button okay so once you selected then again I'm printing the status of male AO button and female a button now tell me what is you expected here so male dat button have selected so
what is the status of here this is true yes what the status of the second obviously false because still it is not Selected yes now we can see the radio button is got selected the first one is got selected so as per our expectation first one is return true because it is already selected second one is still not selected it is still false okay now what I'll do is this time I will select female radio button after selecting female radio button so instead of clicking on male radio button I'm trying to clicking on female radio
button so this will select female radio button okay so now the result will be opposite right so this will return false and the second one returns true because in the radio buttons you can select only one at a time both you cannot select but if it is a checkboxes you can select multiple checkboxes instead of selecting one you can select multiple one or multiple you can select so it has got selected female leer button here yes now you can see yes so after first initially both are false after selecting M button the male is written
true female is return false after selecting female then it is returning male is returning false and female is returning true so this is our expected values okay yes you can use It no problem because without using without selecting the radio button if you apply e selected method it will just return false because it is not selected that's the purpose of using e selected whether that element is selected or not how we will check if you already selected then it will return true anyway if it is not selected it return false so you can use e
selected method before selection or after selection at any time no problem okay you can still use it and before selection if you apply e selected method it will return false and without selecting if you apply e selected method which will return false okay that is a method so is it clear everyone same thing you can try for checkboxes also so for checkboxes also we can check whether it is selected or not so for example let me show you quickly this is the web page on the same web page I have something called newsletter right so
if you open the page freshly and by default this new selector is got selected by default so can we apply e selected on this yes when you apply e selected what is the value it will return true because which is already selected okay let's inspect This okay this is the newsletter element so now I'm applying on the newsletter enabl or not so just observe can say driver do find element by. X paath and I'm I just want to verify is selected or not so I can simply directly I'm using is selected I'm not storing into
another web element because I want to perform only one action and that I can store in a Boolean variable Boolean okay this is what this a newsletter right so newsletter status right now what is the status you are expecting here is true so newsletter checkbox status I'm directly printing this all right so this will return true and for checkbox also if you want to check or uncheck we use click method so now new SL checkbox is true okay so now is it clear everyone so is displayed is enabled is selected so these are the three
methods which are comes under conditional method which are very very important in automation especially when you do validations okay first we will learn individual commands but once you start Creating the test cases you will do validations we will learn validations also okay so is displayed e enabled e selected methods widely used in validations whether the elements are displayed or not element is enabled or not elements are selected or not and E displayed method you can apply for any type of element it can be static element or it can be operational element any type of element
you can apply is displayed e enabled method we can apply on operational methods but it will also work in static uh elements but there is no use okay so most of the times it will apply on the elements which are operatable or operational elements and easy selected method we can apply for radio button checkboxes and drop downs also okay if there is any drop down if the value is not selected from the dropdown then it will return true if it is selected value from the drop down it will return false that is called E selected
okay I will also discuss about drop downs in the coming sessions for now we can skip it so these are the conditional methods three methods now the next one browser methods so far every Everything Is Clear please confirm in the chat box One second everyone conditional methods are clear yes now let us move on to the next one browser commands or browser methods only two methods are there we already discussed close and quit close and quit major difference there only one difference close command will close able to close only single browser close command will able
to close only one single browser whereas quit command will able to close multiple browsers multiple browsers at a time it can close so let me show you an example okay so let's create I'm taking this get methods example okay so I'm trying to remove all these things okay just observe I'm just trying to launch this particular page also I put some weight statement okay now just observe here I'm clicking on some link I'll show you this this web page okay yeah so first of all I'll open this web page and once you open it then
I will click On this link so this will open another browser So currently how many browsers are there two browser windows are there so same action I have done here first I open this page then I click on this element then I will have a two browser windows now let me use driver do close driver. close I'm using okay just observe what will happen I'll put this weight statement here so that you will exactly notice which one it is got closing so two browser windows are open open I'm using close command okay this is my
first browser window yes there is a problem with the synchronization so what I will do I'll put another weight statement after launching my browser okay now you can see two browser windows are open first one second one now just observe the first one is got closed the first browser window which is called as a parent window is got closed the second browser window still alive what does it mean so I already told you one point whenever you open two browser windows the driver will focus on the first page it cannot shift to one page to
another page immediately so even though it Is open another browser window second browser window still our driver is focused on first browser window so that is the reason the command close command is closed only first browser window okay so now I want to close both the browser windows then I can use quit command I can say driver Dot quit this will close both the browser windows one and two let us see okay this is my first browser window just observe after five second browser window is also opened now after 5 Seconds both will be closed
yes both the browser windows are closed so that is a major difference between close and quit so close command can close single browser window and which browser window again in two browser windows are open only single browser window will be closed which one is that wherever the driver is focused okay close single browser window wherever the driver is focused okay and quit command will close all the browser windows right so this is a major difference between close and quit but again based upon my choice I want to close parent or I want to close child
depends on my requirement how we can control We need to know the switching commands how to switch between one page to another page after switching you can close it okay that we'll see later so remember that point interview prospective which is most important so get window handle get window hand along with the switching commands we will use it okay these are all browser commands so three kinds of commands or methods we learned so far get commands or get methods conditional methods and browser methods okay so we also have a navigational methods and then weight methods
in the tomorrow session we will discuss this okay navigational and weight methods weight methods are most important we have implicit weight explicit weight fluent weight and thread do sleep also we'll discuss something advantages disadvantages you will get more in questions on this so tomorrow session we will cover navigational commands and then wait okay so as part of assignment what you guys can do is I will show you one thing assignment so can just go to this web page I'll show you test automation practice blocks.com so go to this page and in this particular page whatever
commands today we learn apply all the Commands so just find out the title of the web page capture this URL capture the page Source okay and what else we learn get the window handles okay and get the window handles IDs and after that try to interact with these elements check boxes check boxes are there and also radio buttons are there you can check enable and disable status of radio buttons and checkboxes and also we can check enable and disable status of the the input boxes okay so you can try this for today's session and tomorrow
I'll give you some more assignments so do some kind of a practice on this so whatever topic so far we discussed just apply these topic on this page so that is a assignment for today and tomorrow we will continue with the rest of the commands navigational and then weight commands Okay so I'll stop here for today's session tomorrow we will continue