so today uh we'll see uh xath locator the last
classes we have seen the basic locators like ID name link text partial link text tag name and
class name and then we also discussed about CSS selector and different combinations of CSS
selector and today we'll see one more type of uh locator which is xath and most important
and most of most of the times we prefer to use xath 80 to 90% of the times we always use xath to
locate the element even in Automation and realtime projects and almost everywhere uh let's see what
exactly xath means and what it contains so how we can write an xath how we can generate an xath and
what are the different types of xath we can create there are multiple things we have to discuss in
this okay let us start so the basic definition what is an exp X path is nothing but it is derived
from the XML path basically the X path Works based on the XML it is derived from the XML language XML
is a extensible markup language it is just like an HTML XML is also another type of a scripting
language from XML xath is got created or designed in shortcut in XML path in shortcut we can call
it as a x paath and what is the definition of the xth X paath is an address of the element xath is
representing an address of the element means what if there is an element on the web page it can be
anywhere on the throughout the web page it can be placed anywhere there should be some address for
that element okay for every element there should be some address and that address we can capture
that is called xath address of the element xath is representing an address of the element okay
from where we will get that xath xath works based on the Dom Dom is nothing but a document object
model so document object model this is the full form of Dom so let us try to understand what
is a Dom Dom is nothing but a document object model which is got created when you browsing the
web page at the run time okay so normally what is happening is how we can browse the pages you
will open the browser and he will you will type some URL like this so as soon as you type URL or
as soon as you hit something and at the run time it will load the Dom structure so now you got a
page so if you try here and you can say inspect so whatever you can see here this is called Dom
okay so here in the elements you can see right this is called Dom d document object model okay so
this document object model this Dom will be loaded at the run time once you browse any web page and
based on this Dom the XML or xath will work also we can capture xath uh from this particular do
docment object model okay so xath is an address of the element and we can capture the xath from
the Dom itself okay sometimes what happens is you have created some xath locator in your automation
script and you have executed and you may get some kind of exception like Dom is not loaded something
like that so what does it mean is that xath will able to capture from the Dom but when you browsing
the page at the time Dom is still not fully loaded so once this Dom is fully generated by the browser
then only xath will able to capture it the element or xath will automatically works if the Dom is
still not loaded completely so even the xath is correct it cannot identify the element and
that cannot be find in the Dom so Dom should be completely loaded and then only xath will work
right so document object model so xath will work based on the Dum document object model now there
are two kinds of xar and somebody's writing just a second okay just a moment all right so xath is an address of the
element Dom is a document object model based on the Dom xath will work okay now so there are
two kinds of X paath we have let us see what are those two types of X paths two types of X path
okay one is called absolute X path absolute X path and this is also called as full X path second
type of X path is called relative X path which is also called partial X paath okay absolute X paath
and partial X path absor X paath means what is also called as full X paath relative X paath is
nothing but a partial X paath these are the two kinds of X paath we have so let me show you how
these xarts looks like suppose I just open open some application here any application you can
just open suppose I want to find xath of this input box okay so you can just right click
on it and uh you can simply say uh here you can say inspect that element so here input is
a tag name there are some more attributes are there right so if you want to capture xath from
the dev tools simply you can write click on this statement and here you can see copy and here you
can see two options copy xath copy full X paath so when I say copy full X paath and then paste
it over here this is called absolute xath okay now let me show you relative xath so for the
same statement again I'm right clicking here go to copy and then say copy xath just copy xath
and then you can see xath like this so this is a relative xath and this is a absolute xath this is
an example for Absol xath this is the example for the relative xath so there are two kinds of xath
which we have one is called absor X path this is an example I'll discuss all the stuff differences
how we can generate all those things just to have some time okay this is a relative X path okay so
this is Absol X path and this is the relative X path okay now if you look at these two x paaths we
can see lot of difference so in absolute xath if you look at here this exper is got generated what
exactly they are if you look at this what is this HTML body header d d input these are all tab these
are all tag names okay if you look at this HTML you can see HTML header body right and these are
all multiple T tags are there and here there is a input so absolute xath contains only the tag names
but where exactly our element is present this is our EXA element which is having input tag right
that is our exact element we are looking for but apart from this tag it is also captured other tag
names which are there in the previous nodes means what if you look at the absolute X path this
is the actual element but from where it is got generated from the HTML then it go to body then
header section inside this there are D inside this another D inside this another D again here
there are multiple DS are there so it is go to Second D again one more D and here we can find the
input act that means Absol X paath will be created created by navigating each and every node till you
reaches the expected node for example let's say here input is tag so what is the root node here
is HTML we are just navigating from the beginning so Absol xath is always start from the root HTML
node we can call it every tag is a node okay node is representing one element so HTML is a root node
and inside this we go to body inside the body we go to header and inside the header there is one
D tag if I look at this uh X paath you can just compare like this so first HTML then body then
header so inside the header there is only one D tag here so there is a One D now if we expand this
D tag little bit like this again there is two D tags are there three D tags are there inside the
D so this is a header header contains One D tag inside this D tag there is one more D tag and you
can look at here this is a main D tag under header and inside this there is another D tag now if you
expand this D tag again there are three D tags now in which D tag is available our element in
the second D tag so we need to expand the second one right so here we can say index D of two and
inside this there is only one D tag and this D tag contains a input tag so here which contains only
one du tag which contains the input so if you look at this absolute xath observed xath will navigate
from the root HTML so till it reads the element it will capture every node or every tag between
the HTML and your element between these two whatever the nodes are available in the hierarchy
basically it will follow the hierarchy structure in that particular tree or hierarchy model it
will capture each and every tag or node till it reaches the element and Absol X paath contains
only tag names okay so this is a Absol X paath it is starting from the HTML node navigated each
and every tag in the hierarchy and then finally it reaches the element here this is called absolute
X paath now come to the relative X path relative X path will directly jump to the element because
in the relative X path we no need to navigate from the root node we will directly jump to the
element by using some attribute so what is the major difference between absolute and relative
xath is absolute xath we never specify any attributes we never use any attributes here just
we use only tag names of the elements but in the relative X path we use something called attributes
we can use single attribute or we can use multiple attributes there are multiple options are there
but we will use mainly attribute of the element and here star star representing a node star star
uh sorry SL SL star is representing the tag name or instead of star we can put the tag name also
no problem and attribute and first it will go to search and in that you can find the input tag
suppose if you look at here this is input and where is this input tag is there in the parent
so this div is a parent so input is not having any ID here so do we have any ID attribute here
no so it is taken parent element by using ID it is create xath for this inside this there is input
tag so you can simply say slash input we can also write direct xath for input if you want to write
simply can specify the attribute so name equal to search is there so instead of ID you can directly
say name equal to search and you can remove this part this is called relative xath okay this is
actual relative xath we just use some attribute of the element inside the xath and what is the
major difference here is absolute X paath will start from the beginning and each and every node
it will capture till it reaches the final node and relative X paath by using the this attribute
it will directly jump to the element and then it will find out it will not navigate from each and
every node okay so this is an example for absolute xath this is an example for the relative xath so
if you want to capture from the dev tools you can simply inspect that element go to the statement
you can right click and copy and then use these two options and suppose if you want to capture
this by using selector Hub then how we can do it there are direct options are available you can
just right click on the element go to selector Hub here and here you can see direct options so ID you
can copy directly name you can copy relative xath you can copy okay and then uh CSS you can copy
absolute xath ABS xath means it's an Absol xath relative xath you can directly copy from here
so you can get it the EXP pass directly from this uh context menu options or you can directly
inspect this element get the selector Hub this is a selector Hub the last class I have shown you
this is selector Hub window right so this is automatically generated if you look at here this
is a x paath relative X paath and where is absor xath if you scroll down here you can see this is a
absor x paath of the element okay you can directly get them from the dev tools or by using selector
Hub or or by using context menu so everywhere options are available you can directly get those
xals but most of the times uh but sometimes it is okay you can capture the xath directly but
sometimes we have to write our own xths I will show you in which in which scenarios we have
to write our own xath okay and always we cannot generate xath for every type of element but there
are certain situations where we have to create our own xals okay let me I'll show you that options
also but as of now this is a b absolute xath this is a relative x paath two kinds of X paath we have
one is called absor xath another one is relative xath okay so if you look at these two types of
xths which xath we will prefer to use any guess absolute xath Rel X there are two kinds of xath in
our automation which xath we will prefer most of the times which xath will prefer okay so people
are saying relative xath we will prefer to use most of the times okay so if I ask why relative
xath is preferred when you compare these two absolute and relative X paath which type of xath
we will prefer is relative xath we will prefer most of the times we'll prefer relative xath okay
yeah it is just a given one example I will explain this relative xath in detail okay so we have
to learn about more about relative xath I'll come to and explain the relative xath in detail
but here I'm just showing types of xath stick to that so we will discuss again individually
with more examples I will give you more examples just hold on for some time okay now why we will
use relative expath why we will prefer relative expath okay there are multiple reasons so many
people will say one single answer that is absolute xath is very lengthy whereas relative xath is
very smaller okay so if I use Absol X paaths in our Automation in many places your code looks ugly
right it's not clean but if I use short xath like this it's very simple and also code looks good
very clean right but this is the answer most of the people will tell but the actual reason is
sometimes Absol xath will may be smaller than relative xath suppose if the web page is very
smaller and there are very few number of elements times your absolute xath will be smaller than
relative xath okay but what is the actual reason behind that why we should use relative xath this
is the most popular inter question so how many types of xths absolute and relative xath and why
which xath we will prefer relative xath we will prefer why relative xath is preferred it is not
because of length of the X path the main reason is suppose if you are using Absol X path let us
say I have used absolute X path how it is going to work how exactly absolute X path Works how it
is going to locate an element for example let's say Absol path everything is a hierarchy right
suppose this is element in this there is another element in this another element in this another
element this other this is the actual element we want to find out but from where the navigation
is started from the root HTML so from here to here it should come again here here here and here
it should find the element and here every tag is representing some element so if I look at here
every tag is representing some element on the web page every node is representing particular
element in the web page so if you're using if you're using absur xath the problem is suppose if
the developer changed something let's say he put some elements like this on the web page developer
can introduce some new element somewhere in the middle of something or developer can change the
location of the web element suppose today logo is present here and tomorrow developer is got to
change the logo position here and these changes keep happens in the real time in the real time
projects on day-to-day basis and the UI changes keeps happens so when the UI changes are happens
or developer is added some element new element okay developer is removed some element existing
element or developer has changed the position of the element these changes definitely will impact
the hierarchy right suppose if this particular got changed into some other position then what happens
this observative xath connection is got connection is got Disturbed right so then what happens the
navigation cannot reach to the El so this is the major problem for the absolute expath okay so
why we should not prefer absolute expath because developer keep doing some changes on the web page
they can add a new elements or they can remove existing element they can do a reposition element
because of these changes the hierarchy will keep impacted and our xath willo will be broken then we
cannot locate our element these chances are very very very uh H so because of those changes our
X paath will impact that's the reason we don't prefer absolute X path okay but don't we have such
problem in the relative x paath no why because in the relative X paath basically it will work based
on the attribute of the element we specify some attribute so SL SL SL will directly jump to the
element whichever is having this attribute so it will not navigate throughout the hierarchy or
throughout all the nodes so even though element is got added some new element is got added or
existing element is got moved the attributes will not change so this xath will always works so that
is the reason relative xath is always referred it is not because of size of an xath it is because
of changes on the web page the changes in the web page definitely will impact absolute xath but
that cannot be impacted relative X paath so that is the reason we always prefer to use relative
X paath okay so very important question so I'm going to write here which X path will be preferred
always we will prefer relative X paath okay now what are the major differences when you
compare absolute and relative xath what are the major differences this is also
another most important interation during the interview so difference between
X paath absolute and relative X paath so difference between absolute and relative
X paath just now we understood one difference what is it one difference we noticed so absolute
xth will navigate each and every node till it reaches the actual element but relative X
paath will directly jump to the element based on the attribute which we provided that's the
one difference apart from this there are some more differences are there so let me put it here
most popular inter equation the first difference observed xath will always start with the single
slash whereas relative xath will always start with the double slash remember this single slash
will navigate only one level but double slash can navigate multiple levels that's the reason in
Absol X path when I use single slash it will go to the only Next Level only one level so under
body there's a header from body to D we cannot directly jump why because we are using single
slashes here and double slash can directly jump to the element okay so Absol xath will start from
single slash relative X path will start with the double slash this is a one important difference so
single slash is always representing the root node that is HTML is a starting node on the HTML that's
a root node absolute exper do not use attributes if I look at here in absolute xath we haven't used
any attributes of the element we used only be tag names it can be any tag name okay in between HTML
root node to input tag whatever the elements are there in between these two it is captured the tag
names of all the elements and it is made a root or it is made a path that's called X paath right so
absolute X path don't use any attributes whereas relative X paath Works based on the attribute it
will use set an attribute without attribute we cannot create a xath but there are another ways to
do it if I don't use attribute but attribute must be there so in relative xath we have to use some
attribute third difference Absol X path Travers through each and every node till it finds the
element so it will start from HTML it will go to each and every node and finally it reaches the
input element and relative X path directly jump and find the element by using at Ute so these are
the differences between absolute xath and relative xath so during interview if anybody ask you you
should explain all three differences so absolute xath start with single slash relative xath will
start with the double slash absolute xath will use attri absolute xath don't use attributes whereas
relative xath will use attributes absolute xath will navigate throughout the Dom whereas relative
X paath will directly jump and find the element in the do so these are the three differences okay
so the performance wise is almost the same even it is Absol xath and relative xath performance
wise there is no much difference okay but user perspective there is a n number of chances are
there in Absol xath definitely will will be broken because developer keeps doing some Chang
on the web page because of that absor XO will always impacted so that's the reason absor XO is
not preferred relative XO is preferred it is not because of uh performance but slight difference
is there but that is negligible per that is a negligible as a user we cannot see that much of
difference when I use OBS relative X paath okay yes attributes in the sense we already know what
what is attribute means we already discussed what is an attribute what are the attributes every
element is having certain attributes right see for example if I look at this input box so what
are the attributes of the element type is one attribute name is an attribute placeholder
is value class is an attribute these are all attributes so xath can use any of these attributes
okay xath can use any of the attribute so that's called attribute so absolute X path use attribute
but sorry relative xath we use an attribute but absolute X paath we don't use any attributes we
use only tags of the elements okay so these are the differences between absolute X path and then
relative X path now absolute X path is very very simple because just it is a hierarchy right and it
can be generated as I said we can just right click here copy and copy full xot this is the option
which is available or else you can directly use selector Hub and copy Absol xath you can use this
option or you can directly go to selector Hub tool and you can get it from the selector Hub here
you can see Absol xath so you can get it from here and if you press enter it will check whether
this xath is able to locating element or not so these are the multiple ways we can capture the
X path but Absol xath is straightforward means what it will directly navigating from the root
node it will generate the xath so now you guys can tell me I will write something here you guys
can tell me the absolute xath how we can write absolute X paath okay let's say I have some node
called a and uh then B and then C so inside this a again I have a sub noes A1 A2 A3 inside the
A3 I have a31 a32 a33 and inside the C also I have a C1 let's say these are all different nodes
okay C3 in the C2 I have again C uh c21 in the c21 I have a C 21 1 okay let's say this is my HTML
hierarchy or Dom hierarchy now I want to locate this particular element now tell me how to write
absolute X path first we will start from the root a slash inside they have a three nodes A1 A2 A3
so which node we have to go here A3 so a/ A3 SL inside the A3 again I have a three nodes a31 a32
a33 which element you want to find third element so a 33 so this is our X path okay similarly
I want to find c21 1 this is the element I want to find then how to write X path starting
node is what a BC this is all comes under this is starting node a BC a BC and again let's say
this is there is a root node inside this uh we have a b and c okay now let me tell you root is
a node from the root we have to to go to the C inside the C we have a three node C1 C2 C3 which
where we have to go C2 C2 slash inside the C2 we have a c21 c21 slash inside this we have a c21
again c21 one so this is how we can write a ab x path from the Dom but it is very challenging
if you have a hug or very complex web pages okay because you sometimes you may have 10 elements
in between you may have 20 30 50 elements if the page complexity is increased obviously the
ABS X path complexi also will be increased so it is not recommended most of the times first
of all but if you still want to write an exact absolute expert you can simply write like this
by using hierarchy we can by based on the Dom we can clearly write our own exports okay this
is simple so we don't need to discuss more about absolute X paath because relative xath is most
important than absolute X paath so now you got some idea about the X path right what is an
Absol X paath basically absur X paath is the complete path we have to write by specifying the
each and every node means each and every tag of the element till we reaches the uh expected
element that is an absolute X path so it is not big thing uh we can simply write a absolute
X path now let us discuss more about relative X PA because that's the most important so let us
discuss about relative X paath and which is also called as a partial X paath so the relative X
paath we can generate automatically and we can also create manually so two different ways we can
create a relative export first approach we can do automatically okay automatically we can create
second option is we can create manually so can do we can create relative xath manual or we can
say our own xath our own xath we can generate okay so automatically means we can use either Dev tools
option okay Dev tools option or by using selector Hub selector Hub we can automatically generate by
D tool selector we can automatically generate so example let's go here and suppose if you want to
create an xath for this logo element you can just right click and inspect and go to the script here
right click copy here you can find copy full xath copy xath so these two options are available
from the dev tools and from the selector Hub if you want to use again just right click on the
element directly go to selector Hub and here you can get these options copy relative x paath copy
absolute xath you can see these two options okay I'm just copying relative X paath for that logo
element and it seems like this see it is used some attribute of the element okay and absolute xath
if you want to capture absolute X path you can just right click and select our Hub and you can
say uh here this is copy ABS X path so this will give you Absol X paath okay so you can directly
capture the xath automatically and if you want to use selector Hub what you can simply do it and
inspect and open the selector Hub tool so here go to selector Hub and in the selector Hub this
is our selector Hub so here you can directly get the element so inspect this element as soon
as we inspected here you can see this is a x paath relative X path and this is a if I scroll
down you can see the absolute xath this is the absolute xath and if you want to verify that xath
is correctly working or not you can just double click here it will copy and press enter and this
will find one element is matching same thing for absolute xath if I go to Absolute X path this
is Absol X path of the element press enter and it is finding the one element so it is very easy
to generate xpaths it can be absolute or relative xath we can easily generate by using Dev tools and
the selector okay but how we can generate manually manually I want to generate my own XO so then we
have to follow a syntax so if you know the syntax you can easily generate our own xox okay so let
me tell you what is a syntax how to generate our own xath I'll give you multiple examples and
syntax is first thing you need to start with the SL slash and you can put the tag name here
tag name of the element in the bracket specify the attribute and value of the element and we
need to start with at theate symbol at theate here attribute name equal to attribute value you
have to specify in single or double quotations so this is a syntax and other is suppose if you don't
want to specify the tag name or if you don't know the tag name you can also put simply star star
representing a regular expression so this is a syntax so tag name is Tag name is not optional
you should specify the tag name or at least you should specify the star if you don't know the
tag name okay and attribute we can specify by using at theate symbol here we use at theate
at theate attribute name equal to value of the attribute and here also at theate attribute equal
to value of the attribute so this is a syntax so if you know the syntax you can write XB for any
element now let me show you how we can write it just a moment okay now let us see how to write a relative
xath for few elements let's go and check any element so in this particular page I want to write
relative xath uh for some element let us say you can take any element let's say I I will take this
desktop image element okay so inspect this element and if you're inspecting this element so this
is the HTML of this T this image right so how to write relative xath for this image what is
the tag name here IMG is a tag name so say IMG SL slash start with a SL slash IMG in the bracket
and what are the attributes are available for this SRC is available but most of the times we don't
use SRC because this is representing the target URL alt property title and class okay and let me
take the title title equal to Macbook so let me capture this this entire thing go back and here
at theate that's it title whatever the attribute is available you can specify equal to the value
of the attribute so this is the relative exp part very simple and you can try this directly whether
it's working or not how we can verify you can go to the selector Hub and you can just paste it
over here then press enter now we can see this x paath is exactly matching with one element okay
so we can simply write our relative xath if you know the syntax of the element so what is the
syntax SL SL even if you put the star also this will work suppose if you don't know the tag name
you can simply put star so this will also find the one element so in the relative xath mainly it
will works based on the attribute you must specify the attribute of the element along with the tag
so if you know the syntax you can easily write our own X paaths for the element and again there
are different types of relative expath different ways we can write there are multiple things like
we can specify multiple attributes we can use some built-in methods in this we can use different
operators and R operators and chain EX parts there are multiple flavors of relative expath
are available so we will discuss them one by one so for everybody is clear got some idea about
the xath what is an xath what are the types of xath how we can create an xath so here you can put
single or double codes so if you put double codes what you need to do is you need to use something
called regular expression like this why because in Java we have to keep this entire xath in double
quotations so double quotations inside the double quotations are not allowed so we should specify
the regular expression by using slash and instead of that you can simply put single quotations okay
put single quotation that is also fine right so this is how we can create relative xath based
on the syntax right so now we'll see different types of xpaths in relative xath only we have a
different flavors we will see all of them one by one by using example so now let's go to Eclipse
directly and then create new package dat 24 inside this I'm creating a new class name
it as a xath demo taking main method and set finish okay so now I'm going to show you
how we can use an xath in our automation with some examples first of all I want
to launch my browser so for that I can say web driver driver equal to new Chrome
driver I'm taking all right so import Chrome driver or you can say control shift o so that
will import required packages and then we will launch our application I can say driver dot
get and here I will specify this open cut demo application this is the URL and how to maximize
the page what's the command driver dot manage dot window dot driver. manage do window. maximize
okay this will maximize the page now so let us try to use xath the first example x paath
with single here I'm showing you all of them are relative xath okay xath with single attribute
xath with the single attribute how we can write suppose this is the input box I want to locate
this is input box I want to locate just inspect this element and there are multiple attributes
are there so I want to create an xath for this element if I go back to the selector Hub you can
write your own xath or else you can capture this xath and if you look at this this is a single
attribute which we have used so how we can use xath driver dot find element by dot xath so
here we have to call X paath method X paath and specify the X paath like this and if you
put double quotations what is the problem in this is you will see some error kind of thing so
why we are getting this error because the double quotations we already used but inside this again
another double quotations we are using this is the problem so you can put the single quote
inside this okay now this is the next path of the element and once you locate an element
then I can pass some value in it let's say I'm passing uh you can pass any anything
so I can pass t-shirts like this okay this is having single attribute so
the relative xath is having single attribute this is an example for single
attribute we can also specify multiple attributes but this we have used only one
single attribute so let's execute and see okay it is started execution yes now we can see there
is a value which is got as sent here input box is recognized fine so this
is one single x paath x paath with a single attribute but sometimes we can
also specify multiple attributes if you want to specify multiple attribute
you can specify so X path with multiple attributes suppose if you want to specify
xath with multiple attributes how we can specify so this is for single attribute no no it is executing very fast
actually I'm using two monitors so that's the reason my browser is opening in my
main monitor so I'm just dragging into secondary monitor so that's the reason
still it is showing like that otherwise it will maximize it okay so let me
run this one more time it is going very faster so as soon as you executed my
browser is open now you can see yeah it is maximized right so now how we can specify
multiple attributes in the xar so to specify the multiple attributes in the X path uh you can
see like this okay I will also copy this uh single attribute X path with single attribute this is
an example so now xath with multiple attributes so if you want to create an xath with multiple
attributes we can still create so if you want to do it you can say open cut application and
then so for the same element I want to specify two attributes then what you can do is go here
and go to selector Hub and here you can write your own X paath so this is the element I want
to write our own xath by specifying multiple attributes SL slash input is a tag name and the
first attribute I'm using uh name name equal to search okay and second attribute if you want to
specify use one more bracket okay and here you can specify at the rate one more bracket at the
rate and you can use any other attribute for this element so I have something called placeholder
so that I can use at theate Place holder equal to and the values are case sensitive exactly you
have to provide so you can see the value of the name is such s is a lowercase character and the
value of the placeholder is also search but the value is started with the uppercase character so
when you press enter this is able to locate an element okay so this is a x path of the element by specifying multiple
attributes we can write our own xal so so which one you have not understood
Vera can you tell me I can repeat so x paath with a single attribute xath with the multiple
attributes if you want to specify multiple attributes you can specify in another bracket so
this is one attribute this is another attribute okay if you put multiple attributes it will
be more stronger so like this also we can use x paath by specifying multiple attributes
so how we can write it now Drive dot find element by do X paath and here I can specify
the X and the dot send Keys here I'm passing the value so this is how we can use x path
with multiple attributes you can specify n number of attributes whatever is available
for the T okay so this is one more example so instead bracket bracket we can use
and that is a different case I'll come to that they are operators end or they
are operators so if you want to specify multiple attributes you can specify like this
so this is one attribute and this is another attribute for the same element okay so this is
another flavor let's execute now run as Java application see my web page is maximized and
then you can see the values got entered okay so xath with the single attribute xath with
the multiple attributes now in the xath we can also use operators we have something
called end or operators X path with and R operators so if one value is correct if one
value is wrong it cannot locate the element both attributes should be correct okay if you
specify multiple attributes even one attribute is not correct this cannot be located the element
it will throw exception so whatever attributes are specify here all the attributes should be true
all the attributes should be correct then only it will able to locate the element okay all right
so now X path with end R operator there are two operators we can use in X path end operator
R operator most important listen carefully end R operator again in the end R operator we can
specify multiple attributes okay for example look at the same input box so this is one attribute
right at theate name equal to search here I'm using something called end operator end end
at the rate placeholder equal to search okay just observe so this is the EXP I have return
and this will able to locate one element let's try to understand this in this x paath i specified
multiple attributes single bracket but I specified something called end operator here so at theate
name equal to search and at theate placeholder is also suchar so how exactly this end operator
works when I use this x paath when it will able to locate the element if both the attributes are
correct then only this xath will able to locate the element it is almost similar to this one okay
but here we use additional end operator so how exactly end means end means first one and second
one both attributes should be correct then this locator will identify the element okay suppose
if I'm using R operator instead of end I say R then then at least one attribute should be matched
suppose this first attribute is correct but second one is not matching will it identify element
or not yes still able to identify similarly the first attribute is not correct but the second
one is correct correct in that case also it will able to locate the element so end operator means
both attributes should be true then only it will able to locate an element in the r operator at
least one attribute should be true at least one attribute should be true then only it will able
to locate the element if one of the attribute is false all both uh if both attributes are false
or both attributes are not matching with any element then finally it cannot locate a element
now if I look at here I'm using end operator so one element is matching so for example uh I'm
giving some incorrect value see Zero element so even though the first attribute value is
correct the second one is wrong that's the reason end operator cannot locate any element
zero elements okay suppose instead of end I'm using r r now able to locate element why because
at least one attribute should be matched then our operator will able to locate a element end means
what both attributes should be matched then only the xath will able to locate the element okay so
you can put multiple multiple attributes not only two attributes you can put multiple attributes 3
4 five also you can put right this is about end R operator end means what both both should be
true then only it will able to locate element or means at least one should be true then only
it will locate operator when it cannot locate if both attributes are not correct then it cannot
locate the element okay so let's try to use in our automation so that is up to you if you want
to use multiple oper multiple attributes you can use that will make your xath very stronger okay
so suppose uh if I use this one end operator that means you are expecting both attributes must
be there you're expecting both attributes must be there in that case you can use end suppose at
least one uh at least one attribute is matching then you can find that element if you want to
find element at least with one attribute you can specify both attributes and even one is okay or
one is match then it can find that element in that particular scenario we can use and or so multiple
attributes make your xath more stronger instead of depending on one attribute you can also specify
multiple attributes that will make your xath very stronger okay so if your element is having one
single attribute right there is no question of using second uh multiple attributes so you have to
use only one single attribute especially suppose you have an Anor tag which is having only one
attribute called HF attribute right so other other than this there is no other choice so in
that case you can specify only one attribute that is again based upon the availability okay
if the attribute is having multiple attributes if the element is having multiple attributes
provided in the Dom you can use it in xar if not provided one single attribute is available
then you can use it okay that's still F even though attribute is not available still you
can write an X path I will come to that part suppose I don't have any attributes for the
element still can we write an X path yes we can still write an xath for the element even
though the attributes are not available I will come to that how we can write okay so xath axis
no here I'm not discussing any xath axis so don't discuss that okay we will discuss xath axis
which is very Advanced concept we will cover in the next session so this I'm just talking
about some basic type of xath today I'm not going to deeper aspects okay just stick to that
right so end or op operators let's go back and let us see how we can use them so the next One X
path with end operator X path with end operator yeah so we can write driver. findind element by.
xath in the double quotations we can specify this XPath right so here end operator we have
to use and Dot send keys of we can pass the value okay so this is how uh we can use
multiple attributes with end operator okay execute okay now maximized now you can see the
values got entered same thing we can try with r operator so if I just look at here R
operator so instead of end I'm saying r r means at least one should be true even secondary is
not correct still it will work fine so what I will do is I make placeholder is some XY Z it
is incorrect but still it will able to locate l okay now we can see the values got entered so
this is a r operator x paath with end R operators okay got the difference everyone so difference
between end or end means both attributes should be true should be matched then only it will able
to locate element R means at least one attribute should be true then only it will able to locate
the element that is a major difference between and R yes if the developer keeps changing the
attributes and all we will try to handle them in different way that is a different concept again
so how we can handle the elements those attributes are dynamically changing that's a different
concept I will come to that part so these are X paaths which we have currently using is for
static attrib rutes if the attributes are not changing they are constant then you can go with
this attributes but initial stages the developer do more more number of changes but once your
build is stable right once you get two three four five builds in every cycle you'll get a new
builds slowly the stability come into picture so once the build is stable then your xath and
attributes everything will become stable so you don't need to change every time but in
initial stages the attributes are El keeps changing in those cases static stuff will not work
properly okay how to handle the dynamic elements I will come to that part that's the next topic
okay this is xath for and or I will cover each and everything guys you don't need to ask before
itself first let us listen first okay once you listen everything once I finish the session then
if you have something to discuss you can ask the question and don't go beyond this topic so if
you already know something keep fight sometime okay don't ask ask anything if you already know
something and you can ask the question at the end of the session because otherwise unnecessarily
other people will be confused I'll go step by step each and everything I will cover okay now and
R operator we discussed with multiple attributes so there is another flavor suppose sometimes we
can also write an xath with inner text what is an inner text suppose uh if you locate any element
inner text inner text will be there for few types of elements so for example let us say let's
take any link suppose here desktops is there so let me inspect this element okay so basically
what is what this desktop is it is a link right anchor tag which is having HF attribute and
class attribute some attributes are there you can use this attribute in the xath but I don't
want to use any attributes of the X paath any attributes of the elements still I want to write
an xath for this link how we can write it so we need to capture the inner text so this is called
inner text this is called as a inner text so by using this inner text we can find the element we
can find the element by using inner text okay so let me show you how we can find this inner text
capture this inner text and we can write X paath like this x paath with inner text so inner text
means what here we have to use something called a method x paath with text method there is a method
is there which is called text so I will write the syntax a little bit change when I use methods
SL slash tag name okay what is the tag name of the desktop element anchor tag right so a in
this I'm not going to provide any attribute I'm not going to provide any attribute simply what
you can do is I can use one method called text equal to what is the value of the text here is
MacBook this is the inner text desktop whatever you want you can find out desktops I'm taking so
you can put desktop so this is also next PATH so have we used any attribute in this x path no
we haven't used any attribute of the element and whatever we have used here this is what inner
text okay the text is a method if the text value of the a is equal to desktops then it will go
and match with that element then it will find that element okay similarly if I want to locate
this MacBook inspect this MacBook link and this is also inner text and tag name is a so without
using attribute also we can sometimes we can write an X path so here we can say text bracket
equal to you can specify the value like this so this is also X paath so by using text method we
can find the element and when this is Possible only if you have a inner text then only it is
possible but if you look at the input box here do we have any inner text for this input box do
we have any inner text for this input box yes or no yes most of the times link text is almost
link text is also we considered as inner text but sometimes inner text doesn't have a link
I will show you that okay so for example if I look at here input box do we have inner text
for this input box do we have an inner text for this input box no we do not have a inner text
for that so we cannot use text method for this element okay suppose I'm uh I'm locating this one
featured feature text do we have inner text for this H3 tag name do we have attribute or do we
have inner text for this element yes do we have attributes for this element attributes no okay
so this is this a link is this a link featured is this a link no this is not a link this is not
having any any attribute it is just a simple and inner text okay so here MacBook is inner text or
not yes this is also link this is also link text and also part also inner text but in this in this
case featured this is not a link text this is not a link text but it is a inner text you got my
point it is an inner text so you understood the difference between this one inner text and Link
text the link L text can be in inner text but all inner text cannot be a links that's the point
I want to convey okay now let me write something like h a anchor tag a HF equal to okay some
htdp is something XY z.com something is there okay and here I'm say click me and closing Anor
now tell me is this a link text or not click me is a link text or not click me is a link text or
not yes it's a link text yes and is it inner text or not is it an inner text or not yes it is also
inner text so this is the inner text and also it is a link text suppose if I write like this div
I'm writing a div no attributes welome come and again D tag is got closed now in this is it a link
text or not is it a link text no do we have inet text here yes you understood now what is the
difference between inner text and Link text so the link text can be an inner text but all inner
text may not be a link text until unless you have this HF attribute you cannot say that is a link
okay so if you have this kind of inner text and if you do not have any attributes so by using
inner text we can still locate an element it is still locate an element without depending on
any attributes still we can locate an element by using inner text how it is possible by writing
a text method okay so let me show you so here x path with text method so how we can write driver.
find element by. xath in the double quotations we have to specify SL slash if you specify the T
tag name you can specify or you can put star no problem and in the bracket text method equal
to the value of the text is what I say MacBook okay so this will able to find the MacBook
element then I will perform the click action on this click action on this MacBook I want to
perform the click action like this because that is a link type of element we can perform
the click action okay let's execute now and first of all let us check this is
working in the Dow tools go back to the page okay now go to selector Hub so I'm just pasting the xath here
press enter yes now it is matching with one element so xath with text method
so now we can directly use it here then run yes now it is successfully clicked so
it is going to the next page right so x paath with text method so here we consider
inner text we consider the inner text we are not using any attributes in this we
are not using any attributes so by using inner text we can still find the element
in the xar okay let me show you one more in the same page I want to capture this text
featured okay I want to print that in my console window that is not error actually that's
application related error so when I click on the MacBook it is if you do manually it is working
fine but when you try to automate because we are doing through automation right it is asking
for some kind of authentication so that's a problem with the application not our code okay
now this link is fine but what about this one featured featured this is just a normal
label it is not a link right so how to capture this inspect and uh inner text right
this is inner text featured is inner text so let us try to capture it so can we do any
operation on that label can we do any type of action on this if it is a link we can
click on it but it is not a link nothing it is just a label so what we can do we
can capture this value text value we can capture and we can print in the console
window right so let's write an xath for this okay sl/ H3 is a tag in
the bracket I say text equal to featured that's it now now one element is
matching now we can use this yeah we can check display status we can also capture the
text value so you can say this is the X paath now let me write driver. find element by. xath
in the double quotes we put this okay now if you want to just verify this display status
you can write is dis displayed is displayed so this will return return true or false so
display status and what is the type of this variable is Boolean type of variable and
then you can print display status true or false okay suppose if you want to capture the
text value of this element so then what you can do dot there is a method called get text do
get text so that will capture the text value of the element that I can store in a string
variable okay or string value that I can print right so I can check the text value uh that
label is displayed or not if it is displayed I can also capture the text value of the element yes you
can compare this value with your expected value by just writing one if condition you can check
this value is correct or not okay let me run it okay now we can see we got output as a true and
also featured so this is how we can capture this sh selector is not related to selenium okay this
is related to some other tools it is no so the selector have is not only for selenium selectors
okay it is also supported some other tools like test Trier play right Cypress locators so all
types of tools are supported as of multiple tools are supported so this sh selector is not
related to uh cenum selector okay right so now we have understood how we can use text method along
with the X path everybody's clear so far in this x paath with text method how we can use and when we
have to use if you have inner text of the element then you can use it and if without using any
attributes we can still write an X path by using text all right so there is another method just
like a text we have another method called contains contains x paath with contains method contains okay so let us see how we can use this
uh contains method very simple let's say I want to locate this input box called search inspect
this element and there are some attributes are available for this element so name placeholder
and so many things right so what I can do is I can write an expo for this like this SL slash
input here I'm not going to specify any attribute I'm not going to specify any attribute but what
I can do is I can say one method called contains method is available contains here we have to
pass two parameters contain method will expect two parameters so first parameter is which
attribute I'm using placeholder and comma the second parameter is the value of the placeholder
so what is exact value of the placeholder is search search is an exact value but here I will
just specify only s e a c that's it and then close this single quotation so this will able to
locate the element so zero element as of now why it is zero element input this tag name is not
correct yeah one element so if I look at this how exactly we have written this what is contains
method will do see when I use contains method specify the name of the attribute and specify
the value of the attribute so when I use contains method I no need to provide the complete value
of the attribute I can just specify some partial value of the attribute so in the strings also
we have a contains method right yes exactly it is a substring in the strings we discussed about
contains method what this will do it will return return the subsection or substring of the main
string similarly the contain method will verify this wherever the placeholder attribute is having
this particular string that will go and match with that element so contains me we can verify the
partial value of the attribute we can verify the partial value of the attribute so whichever
attribute we specify here that attribute contains this one and that will go and match with the
element so this is all about contains method you can use any attribute here but you can
you don't need to specify the complete value you can just specify some partial value that's
called contains method okay let's go and use it here contains X path with contains method so driver dot find element by. xath dot this is
uh input box so I'm using send keys right so if I look at here input is a
tag contains is a method placeholder is an attribute and this is a value of the attribute
is not complete value some partial value I'm provided so this will able to locate element
so this is the contains method contains means it will verify the partial text value of the
element so it is able to locate it same way we have another method called start with X paath it
is almost similar to cont but slight difference is there x paath with start with function
start with start with so in this also we can write same thing so instead of contains I
can say start with and again placeholder and the attribute value starting with sea right
so you can keep that no problem so instead of contains I can also use start with it is
another function or another method available in xath okay now it is got enter the value let
me run one more time there is some exception yeah okay so this time we got some exception so we'll see first of all this particular
X paath is correct or not let's copy this okay see there is a syntax error so red
color Mark is representing a syntax error it is clearly saying selector Hub also can cross
check whether it's valid syntax or not so it is saying invalid syntax now let us check why it is
invalid syntax SL slash input it is I think it is a start starts plural okay it is not start it is
starts starts with placeholder c yeah now it is matching so instead of start you can say starts okay so now it is able to locate element so this
is how we can use start now what is the difference between contains and start with can anyone guess
what is the difference between contains and start withd difference between contains and start with
so in contain method this value which we provided can be anywhere in the string okay actual string
is what see in both the cases what is an actual string search right this is an actual string
that's what expected string so in the contain method we just say only s EA that is a part of
the main string so it is matching with this but in start with also the search is start with sea so
this is also matching so the major difference is cont method will check the string anywhere it can
be beginning or it can be middle or it can be end wherever it is comes it still matches but start
with method will not match like that okay start with method will we have to this particular
string has to be beginning of the string so then only it will able to match okay that is
a major difference between contains and start and one more important thing so this contains and
start with functions we can use whenever you want to locate Dynamic web elements whenever you want
to locate Dynamic web elements you can use start with and contains functions so let me tell you
suppose your attributes are keep changing the values of attributes are keep changing then how
we can locate those Elements by using exp and most important entry questions how we were able
to handle the dynamic elements using XA so here we use something called contains or start with
functions so let me show you an example how we can handle the dynamic elements using start withd
and contains finding very very important scenario handling Dynamic attributes Dynamic attributes
in the sense what the attribute values are keeps changing at the run time so suppose if you are
using some ID in the xath same ID will not be there in the runtime so then xath will definitely
won't work so in that case how we can handle this so let me explain this with some examples so
you guys can also tell me the answers for that let me take let us assume I have some button on
my application my button name is called start I have a start button okay so when you click on
on this button immediately it is turn into stop so most of the times you can notice this kind
of behavior for stop watches when you click on start the stopwatch will start and rotating
whenever you click on the stop it will stop the same button is acting as a start and stop
so once you click on it once you click on it it will turn into stop same button there are no
multiple buttons there is single button and it is changing start to stop again stop to start
okay when the button is in start State let us say the ID value of the button is start okay
when button is turned into stop then ID value becomes a stop this is my scenario so when the
button is in start stage the ID value start when button is in stop state ID value changing stop
so now I want to write one single X path and through that X path I'm able to locate element
in whichever state it is having EI either it can be start or it can be stop in both the states
I want to locate the element by rating a xath then how can we write xath for this there are
multiple ways are there now just tell me one by one Give Me One X path start and stop same
button turn into start and stop again start and stop ID is start and stop stop so
sometimes ID is a stop sometimes ID is a stop then I want to write one single
X path through which I should able to locate element for example if I write
an xath like this whether it's correct or not you tell me SL slash I don't know tag
name I can say star here I'm using something called uh at the rate ID equal to start so
this is the exper I have written so will it work first of all is this x paath correct the
way of writing syntax the syntax the way of writing xath is correct yes xath is correct
but it can locate element only one time that means if the button is in start State then only
it can identify but once it is turning to stop it cannot identify right it cannot identify same
thing if you put stop here then it can identify only if the button is in stop state but once
it is into start State this xath cannot work so by specifying the ID directly we cannot locate
these elements only in one state we can locate but another state the xath will will not work so we
need to write an xath let us use R operator and see there are multiple ways one approach is our
operator let's see SL SL star at theate ID equal to start or at theate ID equal to stop can we
write like this will it able to handle in both the situations yes why because we use R operator
can we use end operator here end no end means both the property should be true but at the
time ID cannot be start and stop right so we should use only R so in case of start the first
attribute will match in case of stop the second attribute will match at least one should match so
this x paath will able to handle this kind of a situation this is one approach this is correct
now another approach by using contains also we can do it by using contains also we can do it how
we can do it contains contains specify the atate ID attribute and we need to identify one common
thing in both IDs what is a commonly there in both IDs what is a common value which we have in
both IDs first two characters are common right St is common so that you can specify here s okay so
then this exper also can identify element in both the states because in even if ID is start still it
is working ID is stop also it is working perfectly fine now another way by using start with function
you can say start starts with at theate starts with at theate ID here I can say again STD so
will it work yes so these are the three different because every ID is starting with st only right
so this also works so we can also handle the Dy attributes by using cond and start with functions
in multiple ways we can handle so these X paath we cannot generate we have to write manually
okay these type of xath we have to create our own okay so very very important so contains
a text yeah that is also same contains a text contains that also you can write so another
way you can do like this SL slash star okay and you can say in the bracket contains in the
contains the two parameters it will take and the text parameter comma here you can put s
so contains text text is nothing but what the text should contains a SD so text method will
capture the text value of the element and that contains St so this we cannot use for this
element way because this will work only for inner text okay the text method will work only
for inner text and links for buttons we don't see any inner text most of the times okay so
that's the reason if there is inner text then it will fine or else it will not work so these
three are appropriate to handle this scenario now I will give you some more examples you
get can tell me when to use contains when to use start with you guys can tell me suppose
I have a name attribute for the element the name attribute is keeps changing so initially
the name attribute is what XY Z 0 01 XY Z 0 01 that is initial stage and after that the same
name attribute is got change like this XY Z 02 XY J 03 XY J 04 or again XY Z 0 01 and XY Z 0
02 like this it keeps changing 1 2 3 4 again 1 2 again 2 one like that dynamically changing then
how can you write an xath for this so tell me one exp yes contains and start with functions
works if there is something commonly there but definitely there is some common thing
will be there whenever you kind some Dynamic kind of a behavior yeah I'll show you more
example now tell me if the name is changing like this how can we handle this attribute
by writing an X can we use contains here contains contains at theate name
contains at theate name what is the commonly there in all the names XY
Z is a common so that you can specify XY Z is a common so this xath is
valid can we use start with start with starts with at theate name comma X wet
so we can use start with only right because all the names are start with XY Z perfectly
fine so change we can use start with also we can use both are valid in this context okay
now 0 0 is also common right so can we write like this 0 0 also common in all the scenarios
contains a name 0 0 can we write like this yes that is also valid but in start with we cannot
write 0 0 why because 0 0 is something in the middle of the string so it should have only
XY Z fine so now another scenario now let's say my name attribute is like this name value is
initially it is 0 0 1 XY Z 0 02 XY Z 0 03 XY Z 0 04 XY Z again 0 0 1 XY Z okay how to write
an X path can we use contains here contains contains yes contains at theate name
equal at theate name sorry contains is a method Open Bracket atate name
is what can put XY Z because XY Z can be anywhere in the string so we can put no
problem can we use starts with starts with no why because the starting values keeps
changing right 0 0 is a common you can you start with with 0 0 that is fine starts
with name 0 0 because every name is starting with 0 0 you can still use but 0 0 1 0 02
you cannot specify because the values are keeps changing okay so contain method you
cannot use start with method you cannot use you can use with one zer suppose if
0 0 not available let's say 0 0 is not there now can we use start with can we
use start with no start with we cannot use okay then I'll show you one
more scenario in this case start with we cannot use only contains uh will work now let me take another example
name equal to 101 XY J 201 1 XY J 31 XY J 41 XY Z yeah now tell
me can we use contains here contains contains we can use because XY Z is a Comm can we use start with
start with we cannot use only contains SL slash star contains and here at theate name
simply you can say XY Z okay so now you understood what is the difference between
start with and contains method so these are the two methods through which we can
identify the elements their attributes are dynamically changing okay now let me use
it in your example we already used okay fine so now let us see uh another type of
X path called chainex path chainex path yeah 01 also use the contains method 01 is
common right yes contains name is 01 01 is common all are valid so now another type of X path
is called chained X path so what is the chain X path and when we need to go with the chain X path
sometimes uh if you're not finding any attributes of the element and even you you are not having
any inner text okay you don't have any inner text and you don't have any attributes for the
element in that case how we can write an xath for the element okay for example let's say here
I'm taking this logo element if I inspect this element you can find IMG tag and there are some
attributes okay so let us assume you don't have any attributes for this IMG you assume you do not
have any attributes for this element then how we can locate element you don't have any attributes
you don't have any inner text so then how we can locate this element so if you don't find any
attributes for the element you need to just go to the parent element okay what is the parent of
this IMG what is the parent of this IMG tag what's the parent y a is an Ang and let us assume a is
also not having any attributes then what we should do again we need to go to another parent what is
the parent of EA div div so the div is having some attribute right so we will start writing xath from
div tag div ID equal to logo can we write xath for this yes so how to write SL slash D atate ID equal
to what is an ID value here is logo so I can say logo this is an xath for the D tag but this xath
is not direct xath for the image but my target is what image I want to look at but image doesn't
have any attributes then I went to parent even parent also not having any then again I go to
another parent so I started from here so I have written xath for this logo then what is the child
item for this div tag a is a child item and for a IMG is a child item so we can say slash a/ IMG
now in this xath what is the target element Target element is what image IMG is a target element but
did we write an direct X path for IMG direct xath for IMG no we have written xath for the parent
from there we have navigator to child from there again navigated to the another child if I look
at this it seems like the combination of relative and absolute xath right so till here this is a
relative X paath from here it is a absolute X path why because we are saying slash slash so
the combination is called chained X paath this is a combination of relative and absolute X path
which is called chained X path chained means what if you do not find any attributes of the element
then we will check the parent element is having some attribute so from the parent we will try to
locate the child element so it is just like this let's say I have some element here this having
another element this having another element now I want to locate this element no attributes then
I will go to parent let's say this is a b c and d go to parent elements if the parent elements
having attribute then you can directly write xath for this and slash you can specify the tag name
of the CH element even this is also not having having any attribute then go to another parent so
here you can find some attribute ID equal to some XY Z then you can write xath for this B like this
slash at the right ID equal to some XY Z and from there you need to navigate two levels slash c/
D like this you can write this is called chain expath this is called chain xal sometimes if you
could not find any attributes of the elements you can try writing the path for the parent element
from the parent element you can navigate to The Chain elements this is called chained X paath
okay so now can we use this element use this x paath yes let me check it in the selector
Hub go to selector Hub and here I'm keeping this yes one element is matching so this is
a EXA element so I can say this is chain X path so driver dot find element
by. XPath and what we can do on this image what kind of actions we can do on the image display status we can verify right so dot is
displayed so we can take a Boolean variable image status so driver. find element TT path is displayed so why is giving an error this will return a Boolean value I think this variable
have used anywhere somewhere okay yeah so now let us print status so this
will verify the status of the image element so chain expath means if the attributes are
not available for the particular element we can write we can take the attributes
of the parent element and write an X path from there we can navigate to the
CH element so that is all about chain X path okay so everything is clear so far so
these are the basic understanding what is an X path okay and how many types of X path which
X path will be preferred and x paath with single attribute and multiple attributes x paath with
end or operators x paath with text function xath with contains function xath uh chain X paath
okay and how to handle the dynamic elements using start with and contains function there are
n number of functions are there but more widely we use start with and contains functions okay
so apart from this there are some more options are there we can say expath access like
following preceding parent child sibling preceding sibling following sibling there are
multiple options we can use along with the xath so in the next class we will discuss about the
xath so what is a main difference between xath and CSS okay so before that let me answer this
question what is the difference between contains and can you write your complete question
I could not understand this so difference between yeah can you write the statement okay so contains
a text so this is a different actually so this this will work only for inner text okay if
suppose inner text we are checking suppose inner text contains something or not if you
want to check you can write text and here you not specify anything nothing right so text
contains nothing this will go and match so contains a text nothing so you can write another
way okay it is not matching with these things okay these scenarios are different but this works
only if you have this is right syntactically this is correct actually this syntactically it
is correct so when this will match if you have any inner text okay suppose I have something like
this anchor tag or suppose I have some D tag like this slash div do we have inner text in this
inner text no okay if you write an xath like this contains SL slash do contains so here text
is what empty there is no inner text so here I'm not putting anything just simple put single braces
empty single braces right so now this will match exactly with with this this element this du tag
because there is no inner text here okay so text value is empty text is representing what empty
no no value so this will exactly match with this okay so another one is this one SL slash contains dot so dot is
also representing a text so this is another way of representing the text
instead of text method you can simply use dot also so dot operator also you can
use instead of text so both are same both are same okay these both are same instead of
text method instead of text you can put dot also so okay the question is we usually use an
attribute that is not repeative how come we have a list of values this is I'm just taking for
an example see I'm not saying one attribute is having multiple values no what I'm saying if the
name attribut is keeps changing okay initially this is a attribute value name values one1 XY and
after some time on the same name attribute is got changed 20 01 XY again same name attribut
is got change something else so sometimes if you refresh the pages the attributes are keep
changing so that's where the web pages normally designed most of the times very if you look at
the complex web pages the attribute values will not be same every time so I'm not saying all the
values at a time okay so initially name values this one let's say after refreshing the page
name values got changing like this and after refreshing again another value are getting
these are the different values are changing for the same attribute in that context I
have taken this example but one attribute cannot have multiple values one attribute is
having only one value at a time okay remember that right so practice this example for today's
session and I will upload one presentation today you guess can go through the presentation and
whatever locators so far we have understood all the locators are specified here this presentation
I will show types of locators and different types of locators with an example all the screenshots
example I have taken everything so this is example for ID so name attribute link text and
partial link text class name tag name and also CSS selectors whatever so far we covered CSS
selector how we can use tag and class tag and attribute tag class and attribute the next PATH
so we have discussed all these Concepts what is next PATH what is Dom document object model so
you can see this is HTML this is the Dom view of the HTML this is actual web page so then
absolute xath what is an absolute xath what is relative xath syntax of relative xath xath
with r operator xath with end operator xath with contains method xath path with starts with
method xath with the text method okay so I'll share this presentation today you can go through
each and every slide and try to understand all the examples in tomorrow session I will continue
xath xath with access yeah so now the difference between CSS and expa what is a major difference
very popular interview question let us say your Dom is like this this is your Dom structure
Okay so if when I compare with cs and X paath CSS will go to only top down approach so CSS will
go from top to down only one directional X paath will multi-directional suppose if there is an
element here you can get this element from by navigating from the top or we can get this
element by navigating from the bottom also in all the directions we can get that element
xath will Traverse throughout all the direction of the Dom whereas CSS will Traverse Only One
Direction so that's a major difference but how xath is Direct in all the directions today we
have seen only one direction from the root node we have navigated each and every node and find
that element from root node and this is again top down approach but how come the Rex paath will
navigate all the directions by using x paath axis concept so in the tomorrow session I will discuss
about this how we can TR davers throughout the Dom in all the directions using xath axis so this
concept we will discuss tomorrow session so there a major difference CSS will navigate only
in One Direction whereas xath can direct in all the directions we can move in all the directions
chain X path goes from bottom to top no no no top to bottom so whatever chain X paath today we
discuss that will go to because we identify parent child and child right so first we have written
xath for the parent from the parent to we go to child element so this is top down only so this
is a top down approach so down to top we can do only by using xath axis in the next class I will
discuss about this okay in all the direction like parent to child child to parent child to child
okay and parent to parent so like child parent and grandparent so child to grandparent also we
can directly go similarly from the grandparent to child also we can directly jump so all levels
of navigations are possible in expar but CSS only top down approach is possible so exper axis
I will discuss in the tomorrow session in detail okay so I'll stop the session
today for here and tomorrow we will continue
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