fetch

How to find XPath in Chrome Browser for Selenium WebDriver



Sharing buttons:

hey guys good morning welcome to learn -

automation calm this is Mukesh today in

this video we'll discuss how to find

expert in Chrome browser this is one of

the short video which I have created so

far because in this video I don't have

much to cover I will simply show you how

to find expert in Chrome browser without

any add-on so in this video I will be

covering small two parts find the XPath

and two small tips these tips are very

important so do not miss them so now

let's get started if you want to find

XPath for any of the web application

then by default in Chrome browser we

have this inspect option right so let me

show you with one of the application

called orange HRM life selected this is

the application if I want to inspect

anything then I have to option either I

can right-click and inspect or else I

can press F tool from the keyboard so

let me go with the Specht inspect way so

this window will open here you will find

couple of options element console source

network so you can see a small option

here this arrow button click or select

an element in the page to inspect it so

just click on it and you will find the

details of any of the web element so

what you need to do just click here and

press ctrl F let me show you in the side

window okay it is again not visible for

you

because you can see this fine den or

fine by string right so what you need to

you can write your XPath here you can

write your CSS other selectors here so

if you are not sure how to write XPath

and CSS you can refer my previous video

as of law let me quickly inspect one

more time and I found this name and ID

so if I write my own XPath that means

says this ID double slash star at the

rate ID equal to this so you can see it

is showing one of one it means one

matching node form okay if I give some

other thing it might find some other web

element so if I give find an input

button with type equal to text you can

see again I am getting only one okay so

you can write XPath CSS here and you

will be able to find the where value and

here you can see options re you can

shift this to the left you can shift to

the right as well and you can shift at

the bottom as well you can see this and

if you want separately you can select

this option it will come separately okay

now another tip is pipeline operator so

this is one of the most important

operator which I use almost in daily

scripting so I can combine two XPath

then one pipeline operator so it will

behave like or either this or this okay

so it happens like if you are running a

script in multiple environments

sometimes locator will change so you

don't have to change all the previous

locators you can write the new locators

as well and you can create a pipeline

operator so if this work is fine

otherwise it will check for other

operator or locators s so let me show

you again if I right-click and inspect

it is coming let me yeah again I will

press ctrl f you can see this small

window comes now let me write XPath

first of all for this same you can see I

have this name so I will say search an

input box where name equal to just now

you can also see this ID also right so

chances are a very half name changes I

can write pipe operator and again I will

write search an input box where ID equal

to 2 this where ID also takes user name

so you can see again one matching node 1

of 1 it means if this works fine

otherwise it will also check this so it

is behaving like our operator so let me

change this to Mukesh so you can see

still it is searching using name right

because it is checking either this or

this if I change both then it will shows

0 0 because now even ID nm both are not

matching so you can use this pipeline

operator multiple time so if any of the

locator works it will find an element

and you will get the element which you

can use in your screw the tip number 2

you can use the indexes ok so what do I

mean by index let's say you have written

some locator or XPath of CSS which is

matching with multiple nodes so in spite

of going through the Java code iterate

the third element second element you can

also customize your X spark using this

parenthesis index approach so let me

show you one example let me click on

this link so you can see I have 3 links

with the same name right click this link

to open or start a new tab

so let me write one XPath I will say

search or certain web element where text

equal to this so you can see with the

same XPath it is matching three

different nodes you can see here right

one of three so this is one if I go to

second one it is matching the second one

if I click one more time it is matching

with the third one correct now if we

want to iterate to second one so I can

use parentheses at startling and

parenthesis at last okay and I can give

the indexes like one so it will get the

first one if I say - it will get the

second one and the third one it's a very

short trick but it works okay so

whenever you are finding multiple

matching nodes so you can use this

indexes approach and you can easily

trade to the number of web elements okay

so in this video via code how to find

ex-parte using SQL you Google get the

inspector just press control f you will

get the small bar you can write to

expose aces in tip 1 we have used 1 type

line operator you can write multiple

XPath so if any of the experts works it

will continue tip number two using

parenthesis index if you have multiple

web elements then you can go with this

approach that's all I have for this

video thank you so much for watching if

you like this video kindly share and

subscribe to my channel have a nice stay

bye bye