so in the today's session uh we're going to learn
uh locators so most important topic and also very big topic so first of all uh we need to understand
what is locator so throughout automation there are only two things are most important first thing
uh we have to identify the elements or locate the elements on the web page so once you identified or
locate an element then we have to perform certain action on that element so these are the only two
things we have to learn from automation because in our web page you can see different type of
elements various types of elements and we have to locate them uniquely let's say you have a two
or three input boxes and whichever input box you want to perform action you want to locate exactly
the same input box similarly if you have number of checkboxes you have to locate a specific checkbox
whichever you want to perform an action so like that there are n number of elements are there
in the web page and you should able to locate a specific element on which you want to perform
the operation and that is possible only through locators and S name is provided various types of
locators to locate web elements and we will try to understand them and the second thing is actions
so to perform the action on the web element again there are so many methods are available once you
locate an element we can perform different type of actions and different type of elements so that
also we have to understand so once you know how to locate an element how to perform the action
then you'll able to automate the test cases okay so the first part is locators so we need to
understand what are the locators are provided by selenium and how can we locate a web elements
using locators but before using locators we need to understand some basic stuff from HTML because
web pages are mostly designed by using HTML HTML is a scripting language hypertext markup language
so we need to understand some basic very basic stuff like what is tag what is an attribute what
are the values we should able to recognize them from HTML and then we will able to work with the
locator so the basic knowledge is required from HTML okay so now so what are the different type of
locators supported in selenium so especially selum supported different type of locators and we can
categorize into two parts so basic locators and customized locators so the purpose of locator is
nothing but what we can identify element we can locate an element so that is a purpose of locator
and there are two kinds of locators are provided basic locators customized locators so basic
locators means what id name link text partial link text class name tag name so these are all
basic locators and these locators are directly supported by selum through methods like when I
use by class The Bu class there are some static methods are there like ID name link text partial
link text class name tag name you can find all the methods in by class itself so these are direct
locators provided by selenium and we can easily find out in HTML suppose if there is an element
which is having ID attribute we can use ID as a locator if we have a name attribute we can use
name attribute and Link text partial link text class name tag name we use these type of locates
the different scenarios for different purposes and we can find everything in HTML itself all
these basic locators we can directly find in HTML itself but sometimes ID may be there sometimes
name will be there ID may not be there okay and linkex partial link text we use especially for
dealing with the links and class name tag name locators we will use especially when you working
with a multiple web elements and group of web elements so different scenarios we will try to
choose a different type of locators but all these things we can find in HTML itself if you look at
an HTML of the page you can find all these things directly on HTML but what is customizer locator
so customizer locators we can generate or we can create our own locators and we cannot directly
find them in HTML and whatever Properties or attributes are available for that element by using
those attributes we can generate our own selectors like it can be expath it can be CSS whatever so
these locators are customized locator we cannot directly find from HTML itself we have to create
our own locators or we can generate locators so which is customizable suppose if there is any one
element if there is element and somebody's written X paath for that element and somebody else is also
return expath for that element both are may not be the same so some guy return expath by using
some properties other guys written expath for the same ele element by using some other propert
properties so these are customizable user defined so we can write our own locators according
to your knowledge CSS and xath so these are all comes under customized locators and again
these two are having so many features so many approaches so many attributes so many methods
we can use so we can call them as a customizer locators we cannot directly get it from HTML just
like a normal basic locators so ID name these are all available as a Properties or as a attribute
for the element class name also is available as an attribute tag name we can see for every element
linkex partial link text also we can directly get it from HTML but we cannot directly get CSS
and expath from HTML so we have to generate it or we can automatic or we can write our own
expath or own CSS so that is a major difference between basic locators and customized Loc s now
the purpose is same whether it is a basic locator or customized locator the ultimate goal is what
we need to locate an element uniquely or you need to identify the web element uniquely that is the
ultimate goal now another question why these many locators are supported to locate an element and
which one we have to use so there is no rule we have to use only this particular locator okay you
can use any type of locator whichever you familiar with ultimate goal is whether you are able to
locate any element or not that's the only thing we need to consider suppose if there is any one
element is there for that element ID attribute is there so you can use ID as a locator or if you
want to write an X paath for the element you can still write an X path by using ID attribute right
you can use CSS also and if suppose if there is a link element is there for that link you can
use Link text or partial link text locator or you can write CSS or Expo also okay there is no
rule like you have to use only this particular locator here in this particular situation or in
this particular locator in this situation it's not like that so whichever locator you familiar
with you can use that locator for that element but why these many locators are provided by
S sometimes uh locator may not work for that element for example let us say ID attribute
is there for that element and even though if I use ID directly sometimes it may not locate
an element if you're working with a complex web pages even though you have direct uh locators
like class name tag name or name or ID still they may not able to locate a web elements in those
cases you can choose for expart CSS but why they may not able to locate an element even though if
we are using right Properties or right attribute because the attributes are keeps changing they
will not be fixed sometimes suppose today the element ID is something tomorrow the same element
you looking for and ID is totally changed okay and when you're refreshing the page the attributes are
keeps changing name is something now after a few seconds or after a few minutes name is different
so in those cases you cannot use static attributes as a locators then you need to choose for either
CSS or xath we can write our locators more Dynamic way and even though the element attributes or
properties are keeps changing still we will able to locate a web elements so that is the reason
cim is provided so many types of locators and whichever is appropriate and whichever locator is
able to locate element uniquely you can use that particular locator okay that is a basic context
but which one we have to use idea or name you can use anything okay you can use anything any uh
any type of locator you can use but ultimate goal is you should able to locate an element uniquely
that's the main uh goal of using locators okay so today we will discuss about a basic locators like
how to use ID name link text partial link text last name and tag name in the next sessions
we will in detail discuss about CSS and xath okay fine so as I said before the basic locators
these we can directly find in HTML itself we can directly find in HTML itself then how to see the
HTML how to see the attributes or properties in HTML how to uh recognize which is dag name which
is attribute which is value so how can we get from the HTML so the simplest way is as soon as you
open the web page let me open some small web page so let us say this is my simple demo application
so if you just right click on on the page and you can see inspect and it will show you Dev tools
window so this is called Dev tools window on the elements tab you can see the HTML and this is the
page source of this particular page okay here you can see everything so whichever element you want
to look suppose I'm using this Arrow Mark as an inspector and uh let me just inspect this logo
and you can see there is a IMG is a tag SRC is an attribute title is another attribute alt is
another attribute class is another attribute if you look at here I don't see ID I don't see
uh name or anything right so in this particular case we choose X paath for the Del okay similarly
if I look at this search button search is a input box so you can see the tag name is input and
here the type attribute is there name is there but we cannot use type attribute directly so if
you look at the locators only ID name link test partial link class name tag is supported whichever
is available for that element you can use it if I look at this name is available ID is not available
so you can use name as a locator to locate a element but you cannot use type you cannot use
placeholder you cannot use class directly okay so you need to recognize them properly what is the
tag name what are the attributes what are their values if you're able to understand this much
from HTML that is enough what is tag name what is an attribute what is the value of an attribute
you need to recognize them clearly from HTML okay so based on that we will able to uh use those
attributes as a locators all right so first thing let us start with the basic locators ID and how
to use name attribute as a locator and then we'll discuss about link text and then partial link text
and after that I will discuss about class name and tag name so these uh locators especially we use to
locate specific web elements a single web elements because ID will be the different from one element
to another element name will be different linkex will be different and Link text partial link text
used only for especially links to locate the links but there is a small difference between link text
and partial link text we will try to understand that okay let me show you practically how can we
use these locators to locate web element so for that I'm taking this application as an example
and I'm going to write a small piece of code uh in which let us try to use locators and in the
previous class we have discussed about whichever element you want to locate there is a method
available in web driver so what is that method name find element so by using driver instance we
can call find element is a method so this method will able to locate an element on what basis it
will locate which needs some input that is locator that we have to pass how to pass the locator using
by class byy do ID or buy. name byy do link text all these methods are available inside the buy
class so whichever attribute you are using you can just call that particular method and provide
that value in the bracket okay so here this is a syntax here we have to pass the locator in
the form of buy class okay yesterday we have understood this now let me try to write a code
for this uh go to eclipse and go to our project web driver project and create a new package for
today so I'm creating new package package name is day22 okay so in this I'm going to create a
new class I'll give some name to this I say locators demo I'm taking main method Also let's
say finish okay so first thing let me try to use this locators for particular elements on the
web page so first of all before that we need to launch our browser and then we have to open
this URL of the application right this is the first thing before inter acting with any element
we have to do this first thing now how to launch my browser we need to create an instance of web
driver that's the first step let us create web driver driver equal to new Chrome driver this is
a statement so we need to import required packages and classes so first we need to import this uh
Chrome driver so sometimes it is not showing as Auto suggestion you can just uh write import
manually so in which package all the classes interfaces available in org open q. selenium so
this is a root package and again there are some sub packages here Chrome driver is a class and web
driver is an interface okay we already discussed that earlier web driver is an interface chome
driver is a class so we have to import required packages now we create a driver instance so with
this this will launch our Chrome browser and then we have to open the URL of the application so for
that what is the method we have to use what is our method yes driver. getet get is a method so in
which we have to pass the URL of the application so let me take this URL demo. openen cut.com
so this is a URL I'm passing so this will open Windows smaller size now I want to maximize this
browser window how to maximize the browser window there is another command yesterday we discussed
dri dot manage method dot again we have to call another method window do maximize remember this
driver. manage. window. maximize so this command will maximize the browser window now so once your
application is ready now we want to interact with some element using different type of locators
first let us look at the name locator how to use name as a locator so if I look at this page
uh I have a search box here so I want to pass some text inside this box I want to pass some text
inside this box so we need to locate this element if I inspect this element like this and see what
are the attributes are available for this element you can see the name attribute is available all
right so name attribute is available so can we use this name attribute yes you can just double
click in this it will select a copy and go back and now how to locate that element by using find
element driver dot find element by dot name so we have to take the name method we have to call
name and here we have to pass the name name of the attribute which we have captured from HTML
okay so this will return web element on top of it what is action we can store if you want to store
this web element on another variable you can store it and that variable type is what web element
now I want to perform some action on this web element what is an action we can perform we can
pass the value into it so we can use one method called Sy keys in this we can pass and some
product name I say mac I'm passing so this is a way we can locate any element by using name
locator and if the name attribute is available then only we can use name if ID is available
then only can use ID otherwise you cannot use this method you need to check Alternatives
okay so let me try to execute this run as Java application so by using using name we are
able to locate search boox element now we can see it is located the element and also
it is provided some text on the input box okay fine now let us see uh some other
element how to locate element using ID let me comment this now if suppose ID is
available for that element so then how can when we locate an element if ID is available
okay so for example let's say here the same application on the same application there is a
logo element here let me inspect this logo element okay if I inspect this logo element okay I don't
have any IDE attribute for this just a second so we need to find some element with ID attribute let me check is there
an element with ID element ID anything so for example let me find something else so if the ID is available we will able to locate
a web element okay so you can see here there is a element with the logo yeah so you can see
here this is the element so this element is having this ID div element actually this this
is a image this is IMG logo element and above this there is another tag called hre because
that logo is having some link and above that actually this is a logo element here this is
ID so now with this ID I just want to locate the element so what action we can perform on the
logo here whether it is displayed or not we can check that logo the image logo is displayed or
not we can check so here there is a ID element ID attribute is there for this logo so let us
try to use this so I'm taking this logo and go back you can say driver dot find element by dot
ID we have to call ID method in this we have to pass the value of the ID now this is a locator
this is the element which will return and what is action we can perform on the image normally we
can simply say displayed status we can check now how can we check the display status whether it's
displayed or not we have a a method conditional method dot is displayed is displayed so this
particular method will return return true or false if it is return true means the logo is
displayed if it is return return false means logo is not displayed so this will return return a
value Boolean value so here I can say logo display status now the type of the variable
is what Boolean variable because e displayed method will return return true
or false now based on that value we can just check system. printet and here I'm
just printing logo display status so like this we can also use ID as a locator to
locate an element if ID is present for any type of element we can use that ID
directly to locate an element let's run this okay so on the UI we have not done anything
but it will just return true or false so if the logo is present it is returning true so this
is how we can simply use ID locator if ID is available you can directly copy the value of
ID attribute and you can use it now the next thing is link text and partial link text link
text and partial link text so these locators are available only for locating links not for any
other element so link text and partial link text we need to understand what is link text and what
is partial link text okay so for example here in this particular uh application uh let us say here
there are so many elements I can see right so here this is my logo and this my search box and these
are all different uh links actually these are all different links so let me locate one of this
L let's say I'm trying to locate tablets here inspect tablets and if I look at this this is the
HTML of this link so wherever you see this a a is representing link anchor tag in HTML wherever you
can see a that is always representing a link and which is associated with one attribute called
hre href is nothing but hyperlink reference so when I click on this link it will go to this
particular page you can see this is the link of Target page HF is always representing the target
page P of that particular link okay so whenever you see a Anor tag which is having HF attribute
and associated with some value which is actually Target link and class attribute is there and here
you can see this is called link text tablet so this is called link text which is called link text
every link you can see the same thing okay for example if I look at this so here the desktops is
a link text desktops is a link text okay so there are two things actually link text inner text you
need to understand the difference so link text is available only for links inner text is available
for all kinds of elements sometimes okay in the text is different but how can we differentiate if
it is a link text the tag name will be a and there is HF attribute will be there and sometimes you
can't see HF attributes and the tag is different tag will be input or D or whatever and you can
see same kind of a text that is not link text that is inner text okay so this is actually link
text so whatever you can see on the UI same thing will be here so here desktops you can see same
desktops and you can see laptops and notebooks if you expand another one you can see laptops and
notebooks so whatever is displayed on the UI as a link in HTML also you can see the same thing so
these are all called link texts so if you want to locate any link on the web page you can use
that link text in a locator okay for example I want to locate this tablets which is basically
a link text and I want to perform click action on this I want to click on the tablets like this
then it will go to Target page tablets page now I want to click on this so before clicking on this
tablets I want to locate this element so when you inspect this element right click and inspect
this is a anchor tag href attribute and Link text is available here so let me capture this link
text link text is not an attribute of the element remember this link text is a not an attribute of
the element if you look at this anchor tag what are the attributes here HF is an attribute class
is an attribute but tablets is not attribute it is a link text now how to use this how to locate
a link by using link text same method driver. find element by dot here you can see there are two
methods link text and partial link text so first let us try to use Link text so when I use Link
text you have to pass the complete value of the link text the full text value you have to pass so
this will able to locate a web element even this also will return web element even link is also web
element but what is the action we perform on this link we have to perform click action so I can say
dot click so this will perform the click action on the link element so by using link text we had just
pass link text here so when I run this this will perform click action on the tablets link and then
it will go to the Target page now we can see it is successfully click on the tablets now it will go
to Target page but what is link text what is the difference which is most popular interv question
also what is the difference between link text and partial link text which one will be preferred to
use so we understood what is link text link text means we have to capture the link text from the
HTML this is the link text and we provided the full text here but when I say partial link text
we no need to pass the complete text value you can just pass some partial value so for example
instead of Link text I'm calling partial link text Dot partial link text if you're calling partial
link text you no need to pass the complete value tablets okay so simple you can pass some portion
of the value like you can pass tab or you can pass tablet like this or you can pass BLS some portion
of the text it is not full link text actually this is the part of the actual link text so here I'm
passing something called table just I'm passing only table but actual link text is what tablets
but here I'm just passing only table so this will also able to look at element and will perform
the action so just observe I'm running as a Java application okay now you can see it is also done
the same job and here the actual link text is what tablets but here we use just a small portion
of the text table still it is able to locate an element but what is the problem with this
we always try to use only link text we don't prefer to use partial link text okay but why
is it so when I use partial link text this may match with multiple web elements because we are
not using the complete text value right we are using some portion of the value let's say I'm
using table and this may match with some other links on the same page then it will be conflict
there may be multiple Elements which are having link text and those link text is also having
same text right so in those cases you may not be able to locate element uniquely that is a problem
with the partial link text so that is the reason partial link text will not be preferable when I
identifying or when I locating the links elements so always try to prefer only link text in the link
text we will provide the complete value so that it will go and uniquely identify the web element so
so what is the difference between link text and partial link text link text we have to provide
the complete link text and when I use partial link text we can pass some partial text of the
link that is the only difference and which one we will prefer only link text we have to prefer
okay so that's the reason I'm just saying don't prefer partial link text so there is no question
like which one we have to you can use both you can use either link text or you can use partial
link text both options are provided but which one is preferred is link text is preferred when you
have to use partial link text suppose if you do not have any other links which are having this
text okay suppose I have a two links and in the both the two links you have the same text in that
case you don't prefer this okay if both to links are different then you have to prefer this okay
so for example let me just tell suppose in your web page I'm taking same example tables there is
a link available tablets there is another link is available okay now in this particular case I want
to locate I want to locate tables I want to locate only tables two links are there assume there
are two links I want to locate tables which one you will use partial link link text or link text
when which one you will use Link text or partial link text when I use partial link text what is
a problem in this that will also match second link right that will also my second link that
is a problem so when you have to use Link text if you're able to locate element uniquely then you
have to use Link text directly okay suppose if you have multiple links and you can see the tables
is also part of here the table part here it is there here it is there in those cases you have to
use only link text link text is preferred in this partial link text is not preferred when I use
partial link text it will be the same okay so this is a scenario link text is always preferable
partial link text is not preferable but if you have single link on the web page Suppose there
is only one link like this and there is no other link which is having table there is no other link
which is having table then you can use this table as part of partial link text that is enough for
this okay so basic difference is in the link text we have to pass full text value if it is a partial
link text we have to just pass some portion of the value and when we have to prefer partial link
text if there are some link and there is nothing is common in those links they can use partial link
text okay suppose I have a submit button okay and I have another button called send button submit
and send button here you can use partial link text because nothing is common in these two except this
first character nothing is same in this both right so you can use partial link text partial link text
of sub you can specify partial link text send you can specify both are totally different so in these
cases you can prefer partial link text but in this particular case always try to prefer link text as
you understood here in this particular case refer to use only link text because nothing is common
in both but here both are totally different so you can use partial link text partial link text
so this is the scenario right so we have have seen how to use name how to use ID how to use Link
text and partial link text so these are all the basic type of locators which we can use to locate
specific web elements or single web elements okay now we also have two more locators class and tag
very very important listen this very carefully tag and class tag name and class so these are the two
locators which we can directly find in HTML just like other attributes tag name and class also we
can directly find in HTML but the tag name and class we will use to locate multiple web elements
or group of web elements not for specific web elements what is the requirement because tag name
can be same for multiple elements if I look at this page see there are so many La tags are there
La tag name is same for all these elements right and you can see multiple D tags also you can see
D tags in many places you can see D tag in many places so most of the times tag names will be more
means multip multiple elements are having same kind of a diagram Suppose there are five images on
this web page all are having same tag name which is IMG and there are multiple links are in this
page every link is having same tag name which is a anchor tag there are multiple input boxes are
there in all input boxes having same tag name which is input same multiple buttons are there
in the same page all buttons are having same tag which is button tag so the tag name will be same
for group of elements or multiple web elements so we cannot use Tag name locator for locating
specific web element it is for identifying or locating group of web elements same thing for
class also class is nothing but a category of elements suppose if you find multiple checkboxes
all the checkboxes are having same value for class attribute and suppose the class attribute is
available for radio buttons the value of the class attribute is same for all radio buttons suppose if
you find multiple drop-downs on your web page all the drop downs are having class attribute but the
value of class attribute is same for all the drop downs so the class is nothing but a category of
elements so same kind of elements are having same value for class attribute that is the reason even
this locator also we will try to use to locate group of elements or multiple web elements so tag
name and class name so these locators especially used to get group of web elements not a specific
web element okay remember that point but what is a use what is a requirement to get group of elements
we always need to locate a specific web element right we will perform action on the web element
we always try to get specific web element but why we need to get group of web element what is the
requirement for that sometimes we need to do some validations on group of web elements for example
on this particular web page I want to find how many total number of links are there or I want to
capture all the links from this web page I want to count total number of links on this web page and
then I will compare with my expected number of links suppose I'm expecting 100 links should be
present on this web page how can we validate so manually it is very difficult thing right because
there are so many links are there we cannot count each and every link and sometimes there may be
some hidden links also there they are not visible on the page so in that case we are we want to
capture all the links from the web page group of links from the web page group of elements from the
web page in that case we will use something called tag name or class and suppose suppose I want to
find total number of images on this page how many total number of images are present so how can we
count we need to capture all the image elements every image is a web element so we need to capture
all the images from the web page and then we will able to count it so in that particular scenarios
we want to work with the group of web elements if you want to capture group of web elements we want
to use a common thing there should be some common thing should be there for every element and that
common thing is what either it can be tag name or class so these things are commonly there for
group of web elements so tag name and class name will be used whenever you want to capture group
of web elements whenever you want to work with the group of web elements so remember this point
so for specific element for Unique element you cannot use Tag name or class tag name or class
will be used for getting group of web elements now I will show you some examples so on this
particular web page okay my requirement is uh I want to capture I want to capture all this header
related links like here is currency phone number and this my account my wish list shopping cart
checkout there are some links are present on the header I want to capture them and I want to find
how many links are there in the header part how many links are there in the header part I want
to just find out so what we can do is we need to find out one common thing between all all of
them so if I inspect somewhere on the header just observe or let us take one element let's take
a four number like this and uh you can see this so what is this here DMD in L this is the class
attribute of this for number and if I look at here there is a li tag and ul ul is representing user
list and Li is representing list item so here if I look at the HTML every Li tag is representing one
element on the header if I look at here see every La how many l are here 1 2 3 4 five L are there
these five L are representing five elements on the header you can just clearly see that whenever
I'm moving the cursor on one Li to another Li it is highlighting the particular element on the web
page you can see that so now I want to find how many header links are there on the web page so I
want to capture all of them how to capture we need to find one common thing what is the common thing
what is a common attribute between them here you can see the class you can see there is a class
attribute is there for Li tag okay so list in line item and again if I use Li tag which is which
is also common right but it will able to get all other links also maybe some other Li items in the
bottom list there are so many links are there even this also we will able to get but I don't want
this fooder links I want only header links so that is the reason I'm choosing this one so this
is a UL which is highlighting the entire part which the each and every list item so now I want
to use this class attribute value which will able to match these five elements okay so what we can
do now let us try to capture this class because the value of the class attribute is same for all
these elements now observe very carefully this is something new you will learn see here we are
using class attribute which is common for all the elements and also second thing is what we are able
to we are trying to capture multiple web elements with that class attribute we are trying to capture
multiple web elements not a single web element so whenever you want to capture multiple web elements
you have to use find elements this is the method okay whenever you want to capture one single web
element you have to use find element when you want to capture multiple elements or group of web
elements you have to use find elements so here we have to use by do class name here we specify the
class name and semicolon so find element method will return one single web element find elements
method will return multiple web elements multiple web elements now what is a written type of here
I'm just keeping one variable here header links now what is the type of this variable if it is a
find element obviously this variable type is web element but here we are using find elements this
will return multiple web elements so if you want to store multiple things into a variable we
have to go with either list collection or set collection and what type of elements it is storing
web element so the variable should be list of web element okay now we need to import the list
collection from java.util and also we have to import web element so the written type of
find elements is what list of web element if you put the cursor it will show you the list of
web element is a written type of find elements list is a what Java collection list is what Java
collection okay so my question is why they make it as a list why can't it is a set so whatever
return type they are mentioning same return type we have to specify here we cannot say set here
they're returning list collection so the variable should be list we cannot use list here why they
make as a list why they can't make it as a set what could be the reason for that yes whenever you
are capturing the elements group of elements there may be some duplicates also available right there
is a chance of having group duplicate elements so if it is a set if it is a list collection it is
is allowed to have duplicates but if it is a set collection it cannot have duplicates so that is
the reason they have designed this find elements method return return type is list of web element
remember this point find element is a method which will return return single web element so the type
of variable should be web element find elements method will return return group of web elements
so the return type will be list means which can have multiple and every value is what web element
type web element type so this is the return type of find elements okay now I captured all the
header links in this particular variable can we find how many are capture how many header
links are there total number of header links how to how to count yes so suppose if you have
some values or elements in the list collection how can we find size of the collection size of
the list by using size method right size is a method which is available for list collection
in Java sessions we discussed about this how to find total number of elements in the list by
using size method so I can say header links do size so this will return return total number of
elements now I'm just printing here so here I can say total number of header links header links I'm
just printing that value and later if you want to use it for validation you can use it so this is a
scenario why we need to capture group of elements and why we need to use a class name because all
these group of elements are having same class name attribute so same value for class name so
I'm using that attribute in the class and which will able to capture multiple elements or group
of web elements then we can find total number of links like this F so let's try to execute now
this is one scenario if you want to capture group of elements if they are having same value for
class attribute we can use class name okay now I can just go back yeah now it is saying seven so
why it is seven here we have only 1 2 3 4 5 right why it is seven because there are some other
hidden links also there even this this is also captured the arrow and uh the symbols are there
right here and they also captured so some hidden uh header links also there they are also having
same class name sometimes they may not able to visible on the page but if you open this page on
the mobile device Sometimes some elements will be displayed so these are the header links which is
captured from the web page yes we can also print each and every Link in the console window and
also we can perform click action on every link and we can also verify the target page so that in
all Next Level okay how to validate the links I will show you that again different concept I'm
not introducing that here so what is link how many types of links what is broken link how to
find it this is all different concept here our focus is only on the locators concept okay don't
go beyond that so we will cover that part in the next sessions so here just trick to only locators
concept don't go beyond that so how to use CSS how to use class name here to locate group of web
elements is this clear everyone how to use class name locator to locate group of web elements yes
so now let me try to show you one more example for example tag name we also have tag name this
is for class class name so now let us see how to use Tag name for getting group of web elements
sometimes uh we want to capture group of elements and you don't see class attribute for them so we
need to find some alternative so we can use Tag name also to locate a group of web elements we
can also use Tag name for locating group of we elment for example on this particular page there
are so many number of uh uh links are present so many links are present in this particular page so
now I want to find all the links including header links this menu links and your product links and
in the bottom of the page also there are so many links are there so I want to find out how many
total number of links present on this particular web page okay so what we need to do is we need to
find one common thing in all the links so what is a common thing which we have in the links is tag
name so if you inspect any link the tag name will be the same that is a a is always representing
the tag name anchor tag even if you inspect any other bottom link for example here about us the
anchor tag is there so for every link there is a same tag name which is a so with this we will able
to capture all the links from the web page so now let me show you how to use Tag name as a locator
to get group of web elements again driver dot which one we have to use find element or find
elements I want to get multiple web elements obviously we use find elements find Elements by
dot tag Name by dot tag name so what is the tag name you're looking for a a is a tag P that's it
end the statement so this will also return all the links in the form of web elements so what is
a return type here return type I'm just keeping links variable here return return type is what
again list of web element this is a return type so now I captured all the links into variable now
the next thing is what we want to find how many links are there so how can we find total number
of links total number number of links total number of links links dot size links dot size because
it is a collection we can use size so this will return total number of links which are present
on this particular page all the links on the web page okay now can just go back now totally 76
links are there in the web page so according to your requirement what you are expecting suppose
you expecting 100 links but here only 76 links are there so after comparison you can make our
test failed and if the links count is same you can make our test passed so like this we can
put some validations on this values similarly let me show you something else so by using tag
name also we can capture group of elements now my requirement is I want to find total number of
images on this web page how many total number of images are there images in the sense the slider
images the product images here the logo images all images how many total number of images are
there in this web page I want to find out so what is the common thing which we have in these
images is again tag name so tag name is always IMG if you inspect any image the tag name of
the image will be IMG wherever you see IMG you can simply find that is a image element okay so
now I want to capture all the images which are present on the web page so what we can do again
we can use same tag name locator say driver dot find Elements by dot tag name tag name is what
IMG so this will return all the images on the web page and again return type is what list of
web element is a read type now if you want to find total number of images you can simply
print here total number of total number of images is what images do size so this will give
you total number of images present on the web page okay so this is how we can simply use Tag
name you get a group of elements so tag name and class name so these two locators especially we
use for getting group of elements or capturing group of web elements and ID name link test
partial link test we can use to get specific type of web elements okay you can also print the
text uh text with size text with the size means what not understood so size in the sense once you capture
all the web elements in a variable we can find the size means which will return total number of
images in this particular collection in case of links we already captured all the links here
so here we find out a total number of links and again if you want to print those link test
you can print again we have to write another for Loop and capture link text from every link
and you can print that link text in the console window okay that is again different validation
and we will discuss these elements separately okay we will deal with all kinds of elements how
to handle input boxes how to handle links how to handle images so we'll individually discuss each
and every web element and that time I will show you what are all validations we can do on the
links how to capture links how to click on the links how to validate Target URLs okay so we'll
discuss them in the separate session because here the concept is what only locators so just stick to
only locators concept okay so guys are you clear about these basic locators how to use ID name link
text partial link text tag name and class name so now I'll discuss one important concept very very
important inter question we already discussed but we will go in detail in depth we understood two
methods find element find elements two methods right so if anybody ask you what is the difference
between find element and find elements most of the people 90% of the people will say find element
will locate one single web element find elements will locate group of web elements or multiple web
element elements this is the only single answer people will say but there are other differences
also there with this two methods so just common answer is what find element will return single
web element and find elements method will return multiple web elements so this is the common answer
most of the people will tell so now let us try to differentiate these two methods in the different
scenarios by taking different scenarios okay now my first scenario is this is most important
listen very carefully first scenario so in the find element in find elements in both the
methods we have to pass locator right in both the methods we have to pass locator using buy. ID
or buy. class or by. tag whatever both the methods will take locator as a parameter so in scenario
one for example my locator whatever locator I'm providing if the locator is matching with a single
web element let us assume whatever locator I'm passing in this methods which is locating single
web element the locator is exactly pointing single web element now I'm using that locator in find
element method and also I'm using that locator in find elements method observe very carefully
so here the scenario is what locator is matching with the single web element on the web page now
I'm using that locator in the find element what this will return return obviously this will
return single web element single web element right because the locator is pointing single
web element and here outside also we use find element both are same so single web element
will be return and what is a return type of this web element is a return return type return
type is what web element this is more clear for us locator is pointing with single web element
find element also will able to return one single web element so ultimately we will get single web
element the return type is web element now the locator is matching single web element but we are
using in find elements instead of find element I'm using find Elements which will able to locate
group of elements but the locator is pointing single web element now tell me what this will
return locator is pointing single web element but find elements method will able to return multiple
elements but locator is pointing with a single web element yes so in the list collection can we
store single value list collection is meant for what to store group of values but still
we can store one single value right in the list collection list contains a single value
also right so find elements will return list collection but because locator is pointing with
a single web element only that element will be returned in the list collection so this will
also return single web element but the return return type is what still it is a list still
is a list but the list collection contains a single web element if the locator is pointing to
multiple elements the list collection contains a multiple web elements if the locator is pointing
to single web element the list collection contains a single web element is this clear everyone so
find element with locator find elements with single locator so here locator is matching with
single web element if it is a find element return type is web element if it is a find elements
written type is still list of web element even though it is rning single web element return
return type still it is list of element okay this is the first scenario now the second scenario
scenario two locator is matching with multiple web elements okay locator whatever it can be
tag name or class name whatever so locator is matching with multiple web elements but
I'm using find element of locator again find elements of locator now tell me the first
one this locator is matching with multiple web elements group of web elements but here
I'm using only find element so what this will return single or multiple elements so here the
locator is pointing group of elements but here I'm using find element will this return group
of elements or single web element listen very carefully locator is matching with group of web
elements or multiple web elements but here find element is able to return only one element
at a time find element cannot return return multiple values but locator is pointing multiple
elements then how it will return what this will return see very important scenario if the
locator is pointing multiple web elements let us say here I have multiple web elements
first element second third four five element elements are there and this locator is pointing
all the elements but I'm using find element method this will able to return only single web
element so even though this locator is matching with multiple web elements because we are using
find element it will return first element on the web page okay whichever element comes first
on the HTML and that element will be return return ultimately the return return type is what
again web element return type is web element got my point so even though that locator is matching
with multiple web elements because we use find element it will return first element on this
list on multiple group of elements whichever element comes first on the web Bas only that
element will be returned so this is the case right so now this is the second case in the
second case locator is matching with multiple web elements but when I use find element
outside still it is rning single web element sorry single web element will be written and
return return type is what return return type is still web element because whenever use find
element that is always return web element now comp the second case the locator is matching with
multiple web elements and outside also I'm using find elements so what this will return single
element or multiple web elements yes this will return multiple web elements because the locator
is matching multiple web elements and outside also we use find elements so obviously it will return
multiple web elements and return type is what rest of web element this is a return type so scenario
two is also clear now third scenario which is most important many interviews people will ask you
this scenario scenario 3 suppose my locator is not matching with any of the elements single or
multiple locator is not matching with any element or elements singular or multiple whatever our
locator is not matching with any of the elements on the web page now I'm using find element of
locator find elements of locator now tell me what the first one will return locator is not matching
with any of the elements locator is not matching with any of the elements but still I'm using
it in the find element what this will return this will return an exception what is that
exception no such element exception no such element exception will be returned okay if locator
is not matching with any of the element on the web page if still use in find element so find element
method will return no such element exception no such element exception will be returned if the
locator is not matching with any of the element now in case of find elements the locator is not
matching with any of these elements locator is not matching with any of the elements on the web
page now what find elements method will return return can you guess what
find elements method will return it will not throw any exception instead it
will just return zero it will return zero elements okay because the locator is not matching with any
of the elements obviously zero so find elements always returns what number of elements number
of ele if no element found obviously the list collection contains what zero so after using
it if you find total number of elements it is returning zero it will not throw any exception
this will not throw any exception the return return is zero so that is a major difference
between find element and find element if the locator is not matching with any of the element
find element method will return no such element exception in case of find elements it will
not throw any exception will not throw any exception it will when you count it it will
just returns zero but it will not throw any exception or find element method will throw
some exception okay so is this clear everyone these are the three scenarios you need to
remember when I use find element and find elements yes it will create an empty list
collection if there is no element obviously the list will create which is doesn't have
anything no values in the list m list will be created okay so this is all about the basic type
of locators we have discussed about ID name link text and partial link text class name and tag
name and along with this we try to understand what are the differences between find element
and find elements and also we have discussed about what is the difference between link text
and partial link text okay so we'll stop here for today's session in the tomorrow session we will
discuss about CSS and expa so these two are very huge Concepts we'll take another two sessions for
CSS and xath and then we will finish the locators concept and this presentation I will share once
we completed this entire topic so there are so many slides are there only related to locators
all the locators have covered in this slide so I will share this slide once we have completed this
concept then you then you'll able to understand this okay yeah so I will stop here for today's
session and uh come to the assignment part for today's assignment uh you guys can try this
very simple based upon today's topics so this is the application you can just open this is your
application URL I think we used this yesterday also demo.com so in this particular page you
have to find total number of links and also you can print them if you want to print you can
print those total number of links okay so okay or else you can just leave this for now in the next
sessions I will tell you so total number of links and total number of images okay and also click on
any product link using link text and product link test you can choose any of the product and then
click on this link like this using partial link text or link text just do one round of practice
so whatever topics we discussed today based on the topics you guys can try this this is assignment
for today and tomorrow we'll discuss uh other type of locators okay so that's all for today's
session I will stop here we'll continue tomorrow
Get free YouTube transcripts with timestamps, translation, and download options.
Transcript content is sourced from YouTube's auto-generated captions or AI transcription. All video content belongs to the original creators. Terms of Service · DMCA Contact