This tutorial provides a comprehensive introduction to Selenium WebDriver, covering its framework nature, advantages, disadvantages, components, and versions. It then delves into practical implementation, including setting up the development environment, writing basic test cases for browser navigation and interaction, understanding locators (ID, Name, Link Text, Tag Name, Class Name, CSS Selectors, XPath), handling dynamic elements, and exploring advanced concepts like shadow DOM and window management.
Mind Map
Click to expand
Click to explore the full interactive mind map
in this tutorial we will learn about the
selenium the selenium framework why is
it called as a framework and
what are its advantages and
disadvantages and its components
so let's get started now here as an
automation tool we will be studying the
selenium webdriver
for this you need to have some prior
knowledge about the java and i have also
explained what are the requirements of
an automation tester
i will give the link in the description box
box
so when you go for an interview as an
automation tester the very first
question that comes to you is what is selenium
selenium
see this is very important before
mastering your skills in selenium you
need to know what is selenium is at
components as advantages and
disadvantages and what are the different
types of frameworks so we will be
so first let us understand what is selenium
selenium
selenium is a portable framework for
testing web applications now here there
are three terms to understand in this
definition one is portable second is
framework third is web application
now what is portable
portable in general uh it means to be
easily transported or relocated that is
the meaning of portable
now what is framework framework
framework
we can divide the word framework into
two parts frame plus work that is if we
work in a frame like here you can see
this house right
this is a house frame or a basic
structure or a supporting structure with
the help of this structure we will be
able to build a house
so this is a framework
so framework just gives us the basic structure
structure
which will uh add our code for greater
functionality of the system now you must
be thinking why do we use framework we
use framework for reusability and we
don't need to build things from scratch
like suppose
let us take up an example if you are
making a dynamic web page and what will
you do you will create folders like suppose
suppose
index.html then style.css validate.php
and etc see the problem here is not that
you have to create folders but the
problem is that you have to follow the
same process again and again
but if you use a framework we don't have
to worry about that
you just need to code your logic and
that's it so that's framework
framework just gives us the basic
structure round
which we will add our code for greater
functionality of the system
okay that's framework
next we have web applications
now there are basically three types of
applications web-based application
desktop application and mobile applications
applications
web-based applications are applications
that can be accessed through browsers
that is like the online forms the
registration forms those are online
based applications
then we have the desktop application the
desktop applications are the
applications in which we we install in
the local system for example the
microsoft word excel powerpoint
that's your desktop application
mobile applications are application we
install our mobile in our mobile through
a play store we download some apps like
whatsapp flipkart amazon those are
mobile applications
now selenium is a portable framework for
testing only web applications selenium
tests only web applications that is the
application that can be accessed through browsers
this also serves as a limitation but we
so moving forward
first thing
we will choose linear because of cost
selenium is free it is open source as
compared to the other tools like qtp and
uft they are a paid
the second point is flexibility
selenium supports multiple programming
languages like java c sharp python ruby
and many more whereas if you go to some
other tool like qtp it supports only vbscript
vbscript
next is the multiple browsers
selenium supports multiple browsers like
chrome firefox safari and many more
whereas if you take qtp as a selenium
tool it supports only chrome
it also supports multiple os like
windows linux apple and many more
the main important point is that why are
we using selenium because it supports
parallel testing now let me tell you
what is parallel testing
the browser will execute the commands in
two ways
one is the parallel execution second is
the cross browser execution now here you
see on the screen parallel execution let
us understand that first parallel
executions are execution in which the
test scripts opens all the browser at
the same time and executes at the same
time it's called as parallel execution
here you can see there's a test scripts
then you can see there are three
browsers over here the first one is
chrome the second is the firefox the
third is the internet explorer
so the test script will open all the
browser at the same time and executed at
the same time this is parallel execution
we will explain i will explain it with
an example just wait first understand
what is cross browser execution
cross browser execution let us take up
an example like suppose
uh in the test script over here it is
written to insert some value in the drop
down menu
so this command will be first executed
in the chrome browser
when the execution is finished that is
when the value is inserted in the drop
down menu
then the firefox browser will be open
and the command to insert the value in
the drop down box will be executed
and when that command is executed then
the internet explorer will be opened and
the command will be executed so this is
called cross browser execution that
means the test script will open the brow
chrome browser first
after two three minutes when the
execution is done it opens the firefox
browser and then after some time it will
open the internet explorer browser this
is cross browse execution cross browser execution
execution
whereas in parallel execution if we have
the same command to insert some value in
the drop down menu then this command
will be executed in all the browsers at
the same time this is parallel execution
now let's move a little deeper towards
the selenium uh we will study the
selenium components which come prices of
the selenium suite total we have the
four components like the ide rc web
driver and grid
let us discuss ide first
now the selenium ide is the most
simplest tool in the entire suites of
selenium it is nothing but an integrated
development environment
see earlier this ide was simply just a
firefox extension and
it's just a play around tool like you
know you just play record functionality
mainly it is useful prototyping and it
is used only for demo purposes
you cannot use ide for creating
automation real-time projects because of
its some limitations we will discuss
those limitations later then the next
component is the rc that is the selenium
remote control
it is used to write web application test
in different programming languages it
interacts with the browser with the help
of the rc server
through which we can interact to the web
browser but this rc server got
deprecated in the selenium version 2
and was replaced by the web driver in
the selenium version 3. we will discuss
that also why it happened
the next component is the selenium web driver
driver
the selenium web driver is one of the
most important component in the selenium suites
suites
it is an api to create and execute the
test cases and it is a successor of rc
basically the selenium web driver is a
collection of open source api and which
will be used to automate the testing of
a web application as i said we will
study the selenium web driver very
deeply the next component is grid the
selenium grid is used to run multiple
test scripts simultaneously on the
different browser and platforms and it
supports parallel testing what is
parallel testing i explained in the
previous slide so because of a grid we
can selenium supports parallel testing
so these are the four components in selenium
selenium
let us discuss the drawbacks of ide the
first drawback selenium id is a
mozzarella firefox plugin which means
the tests can be recorded only in the
firefox browser and not in any other
browser second it's not suitable for
dynamic web pages because it is just a
prototyping tool which works well only
with the static web pages and not with
the dynamic web pages
third data driven testing is not possible
possible
fourth cannot provide detailed test reports
reports
whereas rc the next version of ide can
provide detailed reports
then we cannot perform database testing
through id same because it is just a
prototyping tool it is used for demo and
it is not used for automating web applications
applications
due to these drawbacks rc came into
picture now we have discussed the
components of selenium let's see the
versions of selenium here we have total
four versions selenium version one
selenium version two three and four now
see here we will dig into some history
of the selenium here the selenium
version one
we have the selenium ide rc plus grid so
when jason against introduces selenium
the tool was called as a javascript program
program
he called it as a javascript tester
but he had one major issue that that is
called as the same origin policy
so now what is you must be thinking that
what is this same origin policy
this policy says that when javascript is
executed in the domain
it can access the web pages in that
domain only and it cannot access any
other web page in the another domain
for example suppose like a web page in
the google like if you have a domain
google.com okay so you can access the
search bar the email the drive but
but
that can be accessible but nothing can
be accessible outside the google.com
like if you want to access you yahoo uh
mantra or amazon or any other domain
that cannot be accessible definitely
this is because of some security reasons
so that is why this is called as a same
origin policy
now to overcome this policy remote
control server was designed that is the
selenium rc now the main reason to
create the server was to trick the
browser in believing that the selenium
code in which we are running the scripts
and the web application under test are
in the same domain
now here this same origin policy is
solved so this was the version one of selenium
selenium
where we have the id rc and grid where
the same
origin policy was solved in the version one
one
then comes the selenium version two
here we have the ide the web driver the
rc and the grid see in 2007 when this
when siemens stewart he invented this
web driver now why did he invent this
web driver because the architecture of
the rc was very complicated
and in rc we need a separate server to
talk to this like we need a separate
server to talk to the browser so what he
did is he removed the requirement of the
separate server
and this is the selenium version 2 where
the web driver was introduced now why
you must be thinking like why web driver
and rc is uh introduced over here in the
version 2 because the web driver was in
the development phase and they were
trying to implement it so that is the
reason why we have uh in the selenium
version 2 the ide the web driver the rc
and the grid so in the selenium version
3 we had the ide web driver and grid
here you see that the rc was completely
deprecated and we only have the web
driver currently we have the selenium
version 4 that have many new features
this is the new version of selenium 4
and now it is still in development
recently there was a version
known as alpha version was introduced
and this version was mainly introduced
because of
complete w3c protocol adoption but this
change in protocol isn't going to impact
any of the user because
many major of the browser drivers like
the firefox the chrome driver and they
all are included in the selenium 3.8
version which we are going to use and i
will be also explaining i will be uh
explaining some of the features of the
selenium fourth version we will do that
also like there are many ways to take
screenshot in the selenium 4 version
there are two to three methods
so there are new apis added there are
some ways to access the web elements
also and there are some of the features
that are very new
introduced in the selenium version so
mainly we will be studying about the
selenium webdriver now you must be
thinking why selenium webdriver
now why are we studying the selenium
webdriver for that we need to know the
drawbacks of the
now this is the architecture of the
selenium rc this is the main reason why
we are studying the web driver
so the selenium rc is a test tool that
allows you to write automated web
applications in various programming
languages like java python ruby
so let's see the architecture of
selenium rc
first we need to write the test scripts
in supported languages like java python
or any other supported language
but before writing these test scripts
the major requirement in rc is the rc server
server
so first you need to start the rc server
before you run a core and this rc server
is a separate application
this rc uh is uh responsible for
receiving the selenius command from your
test scripts
it interprets them and then reports the
result back to the script
now i use the word selenius over here
now what is the selenius commands they
are nothing but the commands that are
written in the test scripts are called
as silence commands in id and rc they
are called as syringes commands
now let's look at the browser
interaction how the browser interacts
the browser interactions happens through
the rc server
this rc server is a simple http post and
http get request to communicate okay it
uses the simple http posts and get
request to communicate to the browser
now how this communication happens
this rc server acts like a proxy now you
see there is a complete cycle
starting from your test script then the
rc the rc server injects the javascript
in the web browser
runs your commands takes back the
results sends it to the rc server
and then the result is displayed this
whole cycle gets repeated for each and
every command which is written in the
test scripts this is how the test case
gets executed in the rc server like the
selenium rc tool this is how the whole
cycle goes for each and every test scripts
scripts
now everything was good but why
was rc not good enough to run test
scripts let me tell you why what are
those drawbacks
first time taken for execution of
command is locker why because there is
an additional server rc to so it
executes each and every command is
executed through the rc so it takes a
lot of time for execution
the api supported by rc are redundant
and confusing because
one command means many meaning it has a
lot of meaning for one command like
suppose there is a command called as
click and click at
so which one to use it's very confusing
for the developers then there is
complicated architecture
rc consists of an additional server that
acts as a middleman
also the mobile apps cannot be tested
using rc so these are the drawbacks of rc
rc
now let's see how does selenium
webdriver overcome these drawbacks for
this we need to understand the
architecture of the webdriver
so in the webdriver architecture we have
the test scripts
the web browser and the web server
however we do not have an additional
server for communication like the rc server
server
which we saw in the
selenium rc which makes the architecture
of the web driver very very easy because
we don't have an additional server in
this as you can see there are direct
interactions with the web browser
so as an advantage the selenium does not
use an additional server and since there
is no intermediate server
there then the browser is controlled
directly from the system
system
due to this direct communication the
overall cycle that we saw in the rc
server was which was very indirect
communication since this indirect
communication made the execution very
slow so that's why we have the web
driver in which the execution is faster
than the rc server
as you can see the execution time for
command is shorter due to the simple
architecture now you have seen the
architecture of rc and webdriver let's
compare the selenium rc and the selenium webdriver
let's see in terms of api
now rc is less object oriented api
now the api and rc is very confusing and
redundant for example we have commands
like click or click at commands
which one to use so it was very
confusing for the developers and the
direct browsers
interpreted different commands also
which was very challenging for the
developers working on different browsers
for different browsers browsers there
were different commands
so it was very challenging
whereas for selenium webdriver it is
very simpler api and it is very easier
to use for example we have the click
function to click on the web element we
have the send key command to send text
on very on any web element in the web
page so it has a very simpler api
now let's see in terms of speed selenium
rc is slow in execution
and in terms of speed web driver is
faster in execution
because in selenium rc we have the rc
server whereas in web driver there is no
additional server
next let's let's see in terms of browser
support see rc and webdriver supports
multiple browser but rc does not have
support for html
unit which is a headless browser
now let's see what is this headless browser
browser
headless browser is a browser which does
not have a ui
this helps to make testing more faster
because it does not need a real browser
for testing it does not take
time to load the web elements
so and the headless browser is very
quick so rc and webdriver the support
multiple browser but rc does not support
html unit that is the headless browser
whereas the web driver supports the
headless browser and it is and it makes
the execution move faster next we have
the uh comparison in terms of testing
mobile applications selenium rc does not
support testing of mobile applications
whereas web driver selenium web driver
it supports testing of mobile
application there is an application name
as apm through which we can test mobile
applications so these were the
difference between the rc and the web driver
driver
but every component has its own
drawbacks so let us see the drawbacks of webdriver
webdriver one
one
cannot readily support new browsers but
rc can
and it does not have a built-in command
for automatic generation of test results
see uh it cannot readily support new
browsers there are many new versions
coming up
so this challenge can be overcome
second we don't have built-in commands
for automatic generation of test results
whereas in rc we have we can generate
test results there's a proper format in rc
rc
whereas in web driver we don't but we
can use a third-party tool we can
integrate third-party tools for the
test results generation so now we will
discuss some advantages and
disadvantages of selenium
advantages of selenium
selenium is an open source tool and it
supports multiple operating system and
multiple browsers like chrome safari
internet explorer and many more it also
supports multiple programming languages
like java python c ruby etc apart from
all this we can also integrate the third
party tools in selenium like apache poi
auto i t sql and why do we need to
integrate this we will understand that
in the next slide
here you see the disadvantages of
selenium the first disadvantage is that
it cannot support window-based application
application
it can only support the web-based application
application
but to overcome this disadvantage we can
use a third party tool that is the auto
id or the sql tool the second is that it
cannot support test reports but if we
integrate test ng or extend reports
through that we can generate test reports
reports
third cannot support excel files now you
must be thinking why do we use excel
files we use excel files while we doing
uh while we are doing the
uh data driven testing
we use it because suppose there is a
username and a password field and there
are many test data to it like
for user name you have the admin for
password you have admin at the rate one
two three that's one test data the
second test data third fourth so like
this there can be many test data to
check the expected and the output result
we will match it and then we will pass
the status as
fail or pass so matching those and
results and
communicating the test scripts to the
excel files that selenium cannot support that
that
but through apache pui we can do it next
we have less or no technical support in
selenium because selenium is an open
source tool so there is very less or
technical support but there are many
forums and communities on internet
whereas wherever you can uh
write your queries and you can get your answers
answers
then writing test cases are sometimes
very time consuming because it is just a
programming interface and not an ide see
whereas if you go in other tools like
the qtp and uft though those are id as
well as the programming interface that
means you can
record also you can record also the test
scripts that you have written whereas
over here it is just a programming
interface each and every command needs
to be written so at times it becomes
very time consuming so these are the
disadvantages of selenium till now we
have learnt uh what is selenium why is
it called as a framework we have learned
the versions of selenium their
components that drawbacks and why are we
starting the
web driver
we have also learned what are the
advantages and disadvantages so in the
next tutorial in the next video we will
learn the installation part of selenium
and then we will start the
implementation of selenium we are going
to install the intellij idea ide and
some drivers and jar files for selenium
framework so let's get started
so the first thing that you need to do
is go to google and type
and here you see the first link that we
have that is www.jetbrains.com
www.jetbrains.com
simply just click on this link
so this is the official website of the
intellij idea ide so the intellij idea
is an integrated development environment
that is the ide written in java for
developing computer software and it was
developed by the jet brains
apart from all this the
intellij idea ide has many features like
built-in tools then we then it supports
the jvm languages like the java kotlin scala
scala
and it also has some frameworks like
spring java double e and it also
supports mobile development
and some of the web development like the
html css angular
typescript javascript so these are some
of the features of the intellij idea ide
and in terms of system requirement we
will need a
ram of 2gb minimum and the disk space
that we require is of 3gb of space
we also need to install the java jdk
first and then we will install the
intellij idea ide
so let's install the java jdk first all
you need to do is just type java
jdk download and
the first link that you get is the www.oracle.com
www.oracle.com
just click on this link
and here you see there are different
versions of jdk like we have the java sc
15 we have the java se14
and java s11 we will download the latest
click on jdk download
and click on this windows x64 installer
this one if you're using the mac os then
click on this one but i'm using windows
now here you must accept the license
agreement for java oracle sc which says
that i reviewed and accept the oracle
technology network license agreement for
java oracle se simply just click on this
check box and click on download jdk 50.
so now here you can see that my jdk 15
has been downloaded so let's install this
this
simply just click on it
click on next and
and your
your
jdk will be installed in this file
so just let it be that way just click on next
next
and yeah it's installing now it might
take some time
so now you can see that my java jdk
15 has been successfully installed
so let's check this out simply just
click on close and over here just click cmd
let's see if this has installed or not
properly in our computer so we will
check it through command prompt
simply just type java space
space
so here you can see that we can see that
we have downloaded our java jdk version
15. so once we have installed our jdk we
have to set the environment variables
all we need to do is just go here and write
write
environment variable
and here you can see edit the system
environment variable click on this here
you can see in the advanced tab there is
environment variable click over here
and in system variables go to path
path
click edit and here we will edit the
path how you gonna do that just simply
go where you have installed your jdk
that is
c drive program files java
java jdk
jdk
bin folder open your bin folder
copy this path
and click on ok ok
and over here also ok
so you have set your environment
variable path also
now you will install the intellij idea
id simply uh just go to the official
website of the intellij idea ide and
click on download over here so there are
two versions over here ultimate in
community we will download the community version
here you can see that it started
downloading it might take some time so
just wait now i have download the
intellij idea ide the community version
here you can see now let's install it
simply just click it
click next
next now over here uh
create desktop shortcut yes
for the 64-bit launcher and
update context menu
i'll click this check box create
associations for now i don't want to
create any association
then update path variable restart needed
yes i will add the launcher to the path i'll
i'll
click this checkbox as well
click on install
and here you can see that the intellij
idea ide is getting installed
now here you can see that my intellij
idea community version has been installed
installed
simply click on new project then here uh
just click on java and
here you can see that the java version
15. this is the jdk
that we have installed before
simply just click on next create project
from template i'll just name it as hello
i'll just change the interface of this ide
ide
all we need to do is simply just go to file
file
go to settings and here in the
appearance bar just change the theme to [Music]
[Music]
so this is how you can do it
now let's run a program saying hello world
world
simply just write s out and here you can
see we have the system out.println so
this intellij idea ide has a feature of
autocompleting also just simply by
writing s out it will be system.out.println
system.out.println
and i'll write hello
hello everyone
and i'll click on this button
so here you can see the output that's
hello everyone that's what i printed
over here
so our program has been successfully
executed so this is all about the
intellij idea id
so now we have installed the intellij
idea ide and the java jdk also so we
will install some of the drivers and the
java files that we require in the
selenium so all you need to do is just
you need to go to this official page of
the selenium is
selenium hq i will give all the links in
the description box so it will be easier
click on this link that is a selenium.div
and go to downloads
this is the official website of selenium
and we will download all our drivers and
jar files from this website only
now here first we will download some of
the selenium client and web driver
language bindings now selenium supports
many languages like ruby java python c
we will be working on java you will be
working with java so in order to create
scripts of selenium webdriver you need
to make use of language specific line
drivers so these are the drivers
of java
see here there are some of the versions
that i have told before as well there's
and the alpha version that is recently
released i have discussed about the
versions of selenium in the previous
videos you can check out that
for now uh to download these jar files
we will
and here you can see a zip file has been downloaded
downloaded
here you can see that it is downloaded
simply click on this file
and here you can
see now see i would recommend you to
make a separate folder for java files so
it will be very easy and beneficial for
you because we will be downloading many
java files and drivers
so it will be very confusing and here we
will be giving the paths also in the program
program
when we execute our test cases so it
will be very difficult that which driver
is placed where
so it's better that you would make a
separate folder for those drivers and
jar files
so here in d drive i'm making a separate
selenium jar
jar
okay
so i'll be placing all my jar files and
drivers in this file all i need to do is those
those
files which i had downloaded here you
can see that this is jar file this is
executable jar files
then the next i'll go in lips folder and
over here all these jar files i will
copy it and
okay
so these are the java files which we
downloaded now we will add all these jar
files in the intellij idea ide
so now we will add the jar files so
simply just go on file
go to modules and go to the dependency tab
tab
you can see here add sign this plus sign
click on this
then
go to the file where your jar files are placed
so here you can see all these jar files
which i have pasted in the selenium jar
and drivers
add it
and here you can see the jar file is added
added
click on apply
just wait for a second here you can see
so here you can see now those jar files
so now we have installed the uh jdk we
have set the path for it
and then we have installed the intellij
idea ide and we have added the jar files also
also
so now let's install the drivers just go
to the official website of selenium that
is will be selenium.dave
click on this
so here you can see platform supported
by selenium browsers
now for various browsers we have various
drivers for firefox we have the gecko
driver we
for the chrome we have the chrome driver
for safari we have the safari driver so
mainly i will be
performing operations using the chrome driver
driver
so first we will download the chrome driver
driver
for chrome
just simply before downloading open your chrome
chrome
and be careful about the versions of
chrome firefox and internet explorer you
can do that by just going over here and
click
on about chrome and here you can see my
so i'll be installing the driver of this
version only
be very careful with your drivers
because if you're uh having an old
version of google chrome and you're
downloading a driver of a different
version so it won't work
so it's better check out your version
first update it and then download an
updated driver
so i'll just simply go and write your download
chrome driver for 85.0.4183.21
and here you can see
i'll give the links in the description
box so it'll be very easier for you to download
see here the chrome driver for the
latest is 86.0 but the latest version
that is the stable version that i'm
so
now if you're having linux then click
this one if you're having mac then click
this one and if you're having windows
then click this one i'm having windows
so i'll be clicking chrome driver
underscore windows 32
zip folder
and here you can see it has downloaded
so here you can see this chrome driver
it is a zip file i will extract it
just simply click on extract all and it
will start extracting it
chrome driver all you need to do is just
copy this driver
copy this driver and paste it in your
folder that you have made
so i have made different folders over
here like for chrome driver firefox
driver ie drivers and the jar files
keep things making programs while
implementing the selenium framework when
you are implementing it we need to add
many java files we need to have many
drivers also so if you keep things very
systematic it will be very easier for you
you
so here for chrome driver i have added this
this
now let's go and install the firefox driver
driver
simply just go on firefox again check
your version you don't need to do
anything just click on settings
and here you can see
my version is 81.0 so
so
i'll be downloading the
driver for version 81.0 just type download
download firefox
driver for version 81.0
and here you can see it's
so here this is the driver for the
and here it is again i will copy it
so today we're going to install the
intellij idea ide and some drivers and
java files for selenium framework on
windows 10.
so let's get started
so open your google and type intellij
idea ide
the very first link that we see is the
www.jetbrains.com so click on this link
the intellij idea is an integrated
development environment that is the ide
which is written in java for developing
the computer software
and it was developed by the jet trains
now apart from
all this
intellij idea id also has features like
we have the built-in tools we have the
jvm languages like java kotlin scala groovy
groovy
and also it supports some of the
frameworks like the spring java double e
and it's supposed to mobile development
and web development as well like the
html css angular node.js
so these are some of the features of
intellij idea id
in terms of system requirement we need a
ram of 2gb minimum and disk space that
we require is of 3gb of space
and also before installing the intellij
idea ide we have to install the jdk first
first
so what we need to do is first
type jdk download
now i haven't installed the jdk
i'll show you
go to cmd
and i'll type java
java space
space
dash version
here you can see i haven't installed my
jdk it says that java is not recognized
as an internal or external command or
operable program or batch file
i will
run this command again after installing
my jdk so i'll close this and
here you see we have the www.oracle.com
on this link
and we have different versions of java
jdk we have the java sc 15 we have the
java sc 14 and we have the java s11
we're going to download the
now uh if you have mac os if you're
using mac os you can install
installer you can click this one and if
you're using windows then you can click
this one so i'll i'm using windows
so i click
this file
now here you must accept the license
agreement for oracle java se which says
i reviewed and accept the oracle
technology network license agreement for
oracle java se
you have to simply just click on this
check box and click
on download jdk 15.
so now you can see that my java jdk has
been downloaded so all i'll need to do
is i'll just click on this
so this is the place where your java jdk
will be saved let it be this way and
and here you can see that it is getting installed
installed
it will take some time so
so here you can see that my java
sc development kit 15 has been
successfully installed
so i'll click close
and here i'll type
cmd again
just simply type java space dash
version and here you can see java
version 15
java sc runtime build 15
is been installed
this shows that you have successfully
installed your java jdk 15 and if
it's not coming this way and if you type
this command and this is not the output
of it uh you need to go through the
steps again and install it again
so now we have uh installed our java jdk on
on
on our system so we're going to set the
environment variable simply just type
environment variable and here you can
see edit the system environment variable
here you can see environment variable right
right
here you'll see system variables in this
system variable window
click on path
and click edit
so click on new
and here we're going to enter the part
how we're going to do it
so just go on
c drive on c drive go to program files
and here you can see java
go to java
go to jdk 15 go to the bin folder and
and paste it over here
so this is going to be the new system
click ok
and click ok
and click ok so you have set your
environment variables as well
so we can install the intellij idea ide now
simply go to the official website of
intellij idea ide
and go to download
here we have two versions the ultimate
version and the community version and if
you're using windows go to windows and
if you're using mac then click on mac
and if you're using linux then click on
linux so i'm i'm using windows so i'll
be clicking on windows and we're going
to download the community version simply
just click on download
and here you can see that my intellij
idea become ide the community version is
so now you can see that my intellij idea
the community version has been
downloaded so click on this
click next
so here uh create desktop
shortcut yes for the 64-bit
and update context menu
i'll click add open folder as a project
then create associations i don't want to
create any associations for now
then update path variable that is the
restart needed and add launchers did to
the path
i click
on this checkbox as well
and i'll click next
and here you can see that the intellij
idea ide the community version is
and just click on finish
so here you can see
so here you can see that the intellij
idea id the community version has been
installed and i have created a
shortcut desktop icon over here so i'll
and i'll click i confirm that i have
read and accepted the terms of this user
data sharing i'll just click don't sign
i don't want to share data sharing
so this is the ui theme i'll click the
light one
go to next
here click on java
and here you can see that we have the
java version 15 because you have
downloaded the jdk
so it will be visible here and if you
have not downloaded the jdk it will show
that a link to download jdk like here
you can say see over here download jdk so
so
i have downloaded so it's showing 15
java version 15 has been downloaded jdk
just click on next
uh create project from template
click next
so i'll just write hello
hello world
and
here you can see like if i write s out a
system out dot println so this intellij
idea id has a very cool feature of auto
completing it like if i write s out it's
in system order printer n and there are
many more shortcuts to this we will
learn as and on we keep on programming
we'll keep learning it
so i'll just write hello
world and i'll click on this button that
is the run main
and here you can see here it's hello world
world
so we have installed the java jdk we
have set the variable path also and then
we have installed the intellij idea ide
and we executed a program and it's
successfully executed
so we're done with the installation of
the jdk and the intellij idea id now we
have to install java files and
some of the drivers that we require for
the browsers for the selenium framework
so all we need to do is
just go to the official web page of
selenium that is the selenium hq
here you see we have the www.selenium.dev
www.selenium.dev
click on this
click on downloads
and here we have the selenium client and
web driver language bindings
see to create webdriver selenium web
driver scripts you need to make use of
language specific client drivers
now as we know selenium supports many
languages like ruby java python c-sharp
and javascript so it for
every language we have the specific
client drivers for ruby we have some
client drivers for java we have some
client drivers so we'll be using uh java
we'll be doing selenium with java so
here you can see we have a stable
the latest release that we have the
alpha release for
i have discussed about the selenium
versions also in the previous tutorials
so you can check out that
so we're going to do with java selenium
with java so simply click on download
so here you can see we have this zip
file of selenium java i'm going to
and here we have the executable jar files
files
so it is recommended that
you create a separate folder for the
selenium jar files and the drivers so
i'll be creating a separate folder of
jar files and drivers just created on
any drive like c drive or d drive or
somewhere because we're going to
download many jar files and many drivers so
so
locating them and it will be placed in
somewhere and then locating them and
finding them at that point of time will
be very hard so just simply make a
folder over here
i'll be naming selenium jars and drivers
a folder in selenium jars and drivers
i'll name it jars
and i'll create a separate folder also
name it drivers
and in drivers we're going to install
the chrome driver and the firefox driver
so we'll make the folders for that as well
well
let's make things very systematic
because if you don't do it then it will
be very problematic
problematic
so these this way we have created a new
folder in rd drive that is the selenium
jars and drivers so we have downloaded
we have the first two java files over
here we're gonna copy it
then again over here go to libs
and we have the jar files here also so
and here it is
so we're going to add these java files
now to our
id so just create a new project
project
next i'll name it as selenium
finish so here it is
now we're going to add the jar files
that we have downloaded simply go on file
file
must accept okay just click on accept
and go to modules here
here
you can see dependency tab called dependency
dependency
and here you can see there's a plus sign
right so click on this plus sign and
here you see jars or directories click
go to the
drive where you have created your folder
i've created a d drive and i have named
as selenium jars and drivers
for jars and select all those jars that
and simply just click ok
so here you can see that i have added my
java file over here so just click on apply
apply
click ok
so here you can see that
i can see all my java files over here in
external libraries okay
okay
so we have added the java files also so now
now
let's download the drivers
so what i need to do is
same on selenium hq just go down and
here you can see platforms supported by selenium
selenium
browsers click on browsers and for
different browsers we have different
drivers like for firefox we have the
gecko driver for internet expert we have
the internet explorer driver for safari
we have a safari driver for chrome we
have the chrome driver so basically we
will perform all our test cases in
chrome driver we're going to launch the
chrome driver frequently
but in the next tutorial i will explain
how to launch drivers like the firefox
driver the chrome driver
so for that we need to download the
drivers for it
so all we need to do is just click on
documentation over here
and here you can see
the latest better version that we have
is the chrome driver 86 and the stable
version that we have the 85 now see over
here you need to check your chrome
browser version first so what you need
to do is go on settings and
go to about chrome
and here you can see your version it's
version 85 and if it is not updated then
please update it and then download your driver
driver
because your driver version and your
google browser this chrome browser
should match and if it's not matching
and then your browser will not be launched
launched
so here i have the stable version that
is the 85 version so i'll be clicking
over here
and here you can see
this page if you have linux click over
here if you have mac click on this link
and if you have windows then click on
this link i'm having windows so i'll be clicking
clicking
on this link
here you can see this is the chrome
driver this is the zip file i will
i have the exe file over here
copy this file and paste it in the
folder that you have created
in chrome driver
same way we're going to download the
here we have different versions of gecko
world driver so what you're going to do is just go to firefox
is just go to firefox and check out the version that you have
simply go on settings or general
or general and here you will see that you your
and here you will see that you your updated version that is the version 81
updated version that is the version 81 i'm having 81.0.1
i'm having 81.0.1 so my firefox is updated so i'm going to
so my firefox is updated so i'm going to download the version 81.
and here you will see the driver versions
versions now i'm having windows 64 64-bit so i'll
now i'm having windows 64 64-bit so i'll be clicking this and if you have mac
be clicking this and if you have mac then click this and if you have linux so
then click this and if you have linux so depending upon your operating system
depending upon your operating system just click
just click so here you can see we have the gecko
so here you can see we have the gecko driver it's a zip folder so we're going
driver it's a zip folder so we're going to extract files
and here you can see it is an exe application we're going to simply copy
application we're going to simply copy it and
it and paste it to the folder where you have
paste it to the folder where you have created your
created your drivers folder in firefox driver
drivers folder in firefox driver so today we are going to understand uh
so today we are going to understand uh many topics like first we are going to
many topics like first we are going to create two sets of test cases
create two sets of test cases we will learn how to launch the browser
we will learn how to launch the browser next we will learn how to navigate to a
next we will learn how to navigate to a particular url we will understand the
particular url we will understand the hierarchy of the interfaces and the
hierarchy of the interfaces and the classes in the selenium web driver also
classes in the selenium web driver also we will understand a particular command
we will understand a particular command that is the chrome driver driver is
that is the chrome driver driver is equal to new chrome driver why is it not
equal to new chrome driver why is it not called the best practice okay
called the best practice okay so let's get started
so let's get started so as we know before automating any test
so as we know before automating any test script we have to prepare manual test
script we have to prepare manual test cases first so first we will create two
cases first so first we will create two sets of test cases over here
sets of test cases over here so the first set
in the first set we will have three test cases
cases the first test case is
the first test case is open
open the
the chrome
chrome browser
browser or to launch the chrome browser now
or to launch the chrome browser now whenever we create the manual test cases
whenever we create the manual test cases to open the browser or to launch a
to open the browser or to launch a browser is the first test case it's
browser is the first test case it's always the first test case okay
always the first test case okay next we're going to navigate
next we're going to navigate navigate to
navigate to the url
third the third command is close the browser
browser so these are the three test cases that
so these are the three test cases that we're going to execute one is the open
we're going to execute one is the open the chrome browser that we're going to
the chrome browser that we're going to launch the chrome browser next we're
launch the chrome browser next we're going to navigate to the url
going to navigate to the url www.google.com
www.google.com and the third we're going to close the
and the third we're going to close the browser
browser that we are opening okay
that we are opening okay this is the first set in the second set
this is the first set in the second set we're going to launch the firefox
we're going to launch the firefox browser
browser open the
open the firefox
firefox browser
next we're going to navigate
we're going to navigate to the
to the url
url that is the
that is the ww dot
next is we're going to close the
we're going to close the browser that is the firefox browser
browser that is the firefox browser okay
okay these are the two sets of test cases
these are the two sets of test cases that we have prepared and we're going to
that we have prepared and we're going to execute these test cases today
execute these test cases today as we know uh that the selenium supports
as we know uh that the selenium supports many browsers like the firefox browser
many browsers like the firefox browser the chrome browser the internet explorer
the chrome browser the internet explorer browser safari browser
browser safari browser as we have installed the exe file of the
as we have installed the exe file of the chrome driver and the firefox driver
chrome driver and the firefox driver that we have uh installed in the
that we have uh installed in the previous lecture so we are going to uh
previous lecture so we are going to uh launch the chrome driver and the firefox
launch the chrome driver and the firefox driver and since the process is very
driver and since the process is very similar so once you understand how to
similar so once you understand how to launch a particular browser you can
launch a particular browser you can launch any other browser according to
launch any other browser according to your requirement
your requirement okay
okay open intellij idea ide
open intellij idea ide so in the previous tutorial we had
so in the previous tutorial we had included our jar files in a selenium
included our jar files in a selenium project we had created a selenium
project we had created a selenium project we included a jar files in that
project we included a jar files in that so we're going to continue in that
so we're going to continue in that project itself
project itself so yeah
so yeah as we
as we know yeah we have created two sets of
know yeah we have created two sets of test cases uh
test cases uh we are going to execute it how we gonna
we are going to execute it how we gonna do that
do that first thing
first thing we know for chrome browser
we know for chrome browser the driver that we require is the chrome
the driver that we require is the chrome driver
driver right that we have installed in our
right that we have installed in our computers we have installed the chrome
computers we have installed the chrome driver and the firefox driver so first
driver and the firefox driver so first we will execute for the chrome driver
we will execute for the chrome driver and then i will execute the test cases
and then i will execute the test cases for the firefox driver
for the firefox driver okay for the chrome browser we require
okay for the chrome browser we require the chrome driver
the chrome driver so now what we're going to do first the
so now what we're going to do first the very first step that we are having is
very first step that we are having is the
the open the
open the chrome
chrome browser this is the first step right so
browser this is the first step right so how we're going to do that first thing
how we're going to do that first thing we're going to create the object of
we're going to create the object of chrome
chrome chrome driver
chrome driver okay we're going to create the object of
okay we're going to create the object of chrome driver
chrome driver but how do we refer this chrome driver
but how do we refer this chrome driver object we need to understand the
object we need to understand the hierarchy
hierarchy of the selenium webdriver which has the
of the selenium webdriver which has the classes and the interfaces so let's
classes and the interfaces so let's understand that first
so this is the diagram that we are having
having the selenium provides my number of
the selenium provides my number of classes and the interfaces and we need
classes and the interfaces and we need to understand the hierarchy of classes
to understand the hierarchy of classes and interfaces
and interfaces now to understand this hierarchy we need
now to understand this hierarchy we need to have a knowledge about the interfaces
to have a knowledge about the interfaces and the inheritance concept of java
and the inheritance concept of java now here here you can see this diagram
now here here you can see this diagram right uh in selenium web driver the
right uh in selenium web driver the search context the very first interface
search context the very first interface these yellow boxes are interfaces and
these yellow boxes are interfaces and the green boxes are the classes okay
the green boxes are the classes okay so this yellow box search context
so this yellow box search context this is the super interface of the web
this is the super interface of the web driver and it contains only two methods
driver and it contains only two methods that is the find element and the fine
that is the find element and the fine elements
elements yes these two methods are different it
yes these two methods are different it is not just about a s in find elements
is not just about a s in find elements they are different they are used to find
they are different they are used to find the element on our web page the web
the element on our web page the web elements that we have that is the text
elements that we have that is the text box the drop down menu
box the drop down menu they uh these commands help to find the
they uh these commands help to find the web elements on the web page
web elements on the web page so we will understand that when we
so we will understand that when we practically implement the test cases but
practically implement the test cases but for now let us understand that the
for now let us understand that the search context this search context that
search context this search context that we have is the super interface and is an
we have is the super interface and is an interface that contains abstract methods
interface that contains abstract methods now what are these abstract methods
now what are these abstract methods these methods are the these abstract
these methods are the these abstract methods are the methods that has no
methods are the methods that has no implementation they have only definition
implementation they have only definition there is no implementation of abstract
there is no implementation of abstract methods they just have the definition
methods they just have the definition okay so this is the search context that
okay so this is the search context that is the super interface which has the
is the super interface which has the abstract method find element and the
abstract method find element and the find elements
find elements next we have the web driver interface
next we have the web driver interface okay the web driver interface which is
okay the web driver interface which is extended from the search context okay it
extended from the search context okay it is extended from the search context this
is extended from the search context this means
means that it contains the methods the
that it contains the methods the abstract methods of
abstract methods of find element and find elements method is
find element and find elements method is also in the web driver apart from this
also in the web driver apart from this it also has the other methods like the
it also has the other methods like the get method the quit method close get
get method the quit method close get window handles and many other methods
window handles and many other methods okay
okay so the all these are abstract methods
so the all these are abstract methods that has only body and there is no
that has only body and there is no implementation okay
implementation okay and so these are the uh topmost root uh
and so these are the uh topmost root uh interface apart from all apart from this
interface apart from all apart from this the web driver also has the nested
the web driver also has the nested interface okay it also has some nested
interface okay it also has some nested interfaces like which has windows
interfaces like which has windows navigation target locator timers option
navigation target locator timers option these are also abstract methods through
these are also abstract methods through these methods the through these
these methods the through these interfaces we can perform various uh
interfaces we can perform various uh operations like navigating to the url
operations like navigating to the url maximizing the window and many more okay
maximizing the window and many more okay so the uh the web driver also includes
so the uh the web driver also includes the nested interfaces
the nested interfaces next
next we have the remote web driver this is a
we have the remote web driver this is a fully implemented class
fully implemented class okay which implements the interface web
okay which implements the interface web driver here you can see it implements
driver here you can see it implements the web driver interface okay
the web driver interface okay now this web driver or remote web driver
now this web driver or remote web driver this remote web driver is a fully
this remote web driver is a fully implemented class here you can see it's
implemented class here you can see it's a fully implemented class where all the
a fully implemented class where all the abstract methods coming from the search
abstract methods coming from the search context
context coming from the search context and the
coming from the search context and the web driver are implemented in this
web driver are implemented in this particular class because obviously when
particular class because obviously when we create abstract classes right so
we create abstract classes right so these uh when we create abstract methods
these uh when we create abstract methods we have to use those methods we just you
we have to use those methods we just you just don't have to keep it you will use
just don't have to keep it you will use it that is why there is no
it that is why there is no implementation and only definition in it
implementation and only definition in it as i said your core java knowledge will
as i said your core java knowledge will be required over here to understand this
be required over here to understand this hierarchy so that is why we
hierarchy so that is why we need to have the knowledge of
need to have the knowledge of inheritance and uh
inheritance and uh interface faces of core java so the
interface faces of core java so the remote web driver yeah so the remote web
remote web driver yeah so the remote web driver contains methods of the search
driver contains methods of the search context and the web driver in addition
context and the web driver in addition also it implements a javascript executor
also it implements a javascript executor and takes screenshot
and takes screenshot okay so it uh implements these
okay so it uh implements these interfaces also which has abstract
interfaces also which has abstract methods on its own and we will we can
methods on its own and we will we can implement those extract extract methods
implement those extract extract methods so to the conclusion we can say that the
so to the conclusion we can say that the remote webdriver is a fully implemented
remote webdriver is a fully implemented class which contains the abstract
class which contains the abstract methods of the web driver interface and
methods of the web driver interface and the search context interface and it
the search context interface and it takes screenshot
takes screenshot interface and the javascript executor
interface and the javascript executor okay
okay so this is about the remote web driver
so this is about the remote web driver now here you can see these classes these
now here you can see these classes these classes are the
classes are the uh
uh browsers that we have of selenium
browsers that we have of selenium selenium supports many browsers you know
selenium supports many browsers you know right the firefox browser the internet
right the firefox browser the internet explorer browser the edge browser safari
explorer browser the edge browser safari browser
browser so the remote web driver it extends
so the remote web driver it extends these classes and here you can see these
these classes and here you can see these classes are the web browsers that we
classes are the web browsers that we have that is the firefox browser
have that is the firefox browser internet explorer browsers
internet explorer browsers okay
okay so now uh there are various versions of
so now uh there are various versions of selenium as i told in the previous
selenium as i told in the previous tutorial from fourth version here you
tutorial from fourth version here you can see this is the chromium driver and
can see this is the chromium driver and chrome driver right from the four fourth
chrome driver right from the four fourth version the chrome driver extends the
version the chrome driver extends the chromium driver this has happened from
chromium driver this has happened from the fourth version they had made some
the fourth version they had made some changes they had included a chromium
changes they had included a chromium driver also which uh
driver also which uh through which the chrome driver will get
through which the chrome driver will get extended
extended so these were the changes in the fourth
so these were the changes in the fourth uh
uh release of selenium
release of selenium so this is the hierarchy of selenium
so this is the hierarchy of selenium cluster interface in which we have the
cluster interface in which we have the uh super interface that is the search
uh super interface that is the search context then we have the web driver
context then we have the web driver interface which has which includes uh
interface which has which includes uh nested interfaces also which has many
nested interfaces also which has many abstract methods like windows navigation
abstract methods like windows navigation target locator timeouts options
target locator timeouts options then we have the remote web driver which
then we have the remote web driver which implements the
implements the [Music]
[Music] interface webdriver
interface webdriver and it also
and it also implements the javascript executor and
implements the javascript executor and the take screenshot
the take screenshot interface next we have the um
interface next we have the um next we have the browsers these are the
next we have the browsers these are the browsers which is supported by the
browsers which is supported by the selenium and the remote web driver
selenium and the remote web driver extend these classes these are classes
extend these classes these are classes okay remember the remote web driver and
okay remember the remote web driver and these browser are the classes whereas
these browser are the classes whereas the search context web driver nested
the search context web driver nested interfaces take screenshot and
interfaces take screenshot and javascript executor are the interfaces
javascript executor are the interfaces okay this so this is the complete
okay this so this is the complete hierarchy of the selenium class and the
hierarchy of the selenium class and the interface
interface so now
so now let's move to the
let's move to the program
program so now over here uh for opening the
so now over here uh for opening the chrome browser the first thing that we
chrome browser the first thing that we did over here is we created a object of
did over here is we created a object of chrome driver right now how do we refer
chrome driver right now how do we refer this object
this object here
here in the
in the so remember this chrome driver is a
so remember this chrome driver is a class
class right as we as shown
right as we as shown in the hierarchy it is a class
in the hierarchy it is a class now here
now here just refer to this hierarchy again and
just refer to this hierarchy again and here we can see that the web driver
here we can see that the web driver is the parent interface
here you can see that the web driver is the parent interface and now you must be
the parent interface and now you must be saying no the remote driver
saying no the remote driver the remote web driver is the parent but
the remote web driver is the parent but whatever talking about i'm talking about
whatever talking about i'm talking about the interface focus on what i'm saying
the interface focus on what i'm saying i'm talking about interface the web
i'm talking about interface the web driver is the parent interface and the
driver is the parent interface and the remote web driver is a class okay
remote web driver is a class okay remote web driver is a class and the web
remote web driver is a class and the web driver is an interface so your the
driver is an interface so your the parent interface will be web driver
parent interface will be web driver so the web driver interface will give a
so the web driver interface will give a reference to the chrome driver how i'm
reference to the chrome driver how i'm going to write webdriver
going to write webdriver i will give a reference like driver is
i will give a reference like driver is equal to new chrome driver
equal to new chrome driver so now uh your in this command
so now uh your in this command web driver driver is equal to new chrome
web driver driver is equal to new chrome driver we are using uh the dynamic
driver we are using uh the dynamic polymorphism concept
polymorphism concept in which the child class object child
in which the child class object child loss object that is the chrome driver
loss object that is the chrome driver is referred by the parent interface that
is referred by the parent interface that is the web driver through a reference
is the web driver through a reference variable and that reference variable is
variable and that reference variable is called as driver
called as driver okay
okay so this is how
so this is how we are opening the chrome browser so
we are opening the chrome browser so let's run this command first
so our chrome browser is not launched why
our chrome browser is not launched why let's see
let's see here it shows an error which says
here it shows an error which says illegal state except exception
illegal state except exception which says the path to the driver
which says the path to the driver executable must be set by the
executable must be set by the webdriver.chrome.driver system property
webdriver.chrome.driver system property okay this is your error the path to the
okay this is your error the path to the driver executable must be set by the web
driver executable must be set by the web driver
driver dot chrome dot driver system property
dot chrome dot driver system property so here it says that i have to define a
so here it says that i have to define a property
property a system property and to define this
a system property and to define this system property we have a system class
system property we have a system class so i will write
so i will write system
system dot
dot set property
set property now this set property command has
now this set property command has two values need to be entered over here
two values need to be entered over here uh one is the string key and is the
uh one is the string key and is the string value
string value in the string key what we have to enter
in the string key what we have to enter it's given over here itself
it's given over here itself webdriver.chrome.driver we will simply
webdriver.chrome.driver we will simply copy this
copy this and paste it over here this is your
and paste it over here this is your string key
string key whereas the value will be the part where
whereas the value will be the part where your executable file is saved that is
your executable file is saved that is the chrome driver
the chrome driver so in my case i'll go to
so in my case i'll go to d drive syrian jars and drivers
d drive syrian jars and drivers drivers and the chrome driver because
drivers and the chrome driver because we're launching the chrome driver so i
we're launching the chrome driver so i will simply just copy this part
will simply just copy this part and i will paste it over you
and i will paste it over you change the slashes
change the slashes okay and we're gonna include our file
okay and we're gonna include our file name over here
name over here our file name is
our file name is chrome driver
chrome driver okay
okay so we're gonna write chrome driver
so we're gonna write chrome driver dot exe now if you're using mac you
dot exe now if you're using mac you don't need to write exe because mac does
don't need to write exe because mac does not support exe files so there's no
not support exe files so there's no requirement to write exe but if you're
requirement to write exe but if you're using windows then you're going to write
using windows then you're going to write exe
exe okay we're going to execute this
okay we're going to execute this statement now so here you can see
statement now so here you can see my chrome browser is launched you can
my chrome browser is launched you can see this chrome browser it is launched
see this chrome browser it is launched which says chrome is being controlled by
which says chrome is being controlled by automated test software now this chrome
automated test software now this chrome browser
browser and this chrome browser the
and this chrome browser the original chrome browser these two chrome
original chrome browser these two chrome browsers are different here we cannot
browsers are different here we cannot see any tab which shows that chrome
see any tab which shows that chrome browser is being controlled but over
browser is being controlled but over here you can see chrome is being
here you can see chrome is being controlled by automated test software
controlled by automated test software there's a tab over here
there's a tab over here okay so this is the difference between
okay so this is the difference between the uh
the uh chrome browser that we are launching
chrome browser that we are launching through automation and the chrome
through automation and the chrome browser that we have originally on our
browser that we have originally on our computers
computers so i'll just close this
so we have launched the chrome browser and yes
and yes one important question
one important question that you must be thinking is uh by
that you must be thinking is uh by looking at this uh
looking at this uh diagram now over here you must be
diagram now over here you must be thinking as i said that the parent
thinking as i said that the parent interface is the web driver but
interface is the web driver but you're the super parent interface that
you're the super parent interface that is the search context is also there so
is the search context is also there so why are we not writing
why are we not writing a search
a search context
context driver
driver like i'll just write
like i'll just write driver1
driver1 equal to new
equal to new chrome driver now this command is also
chrome driver now this command is also correct i'm not saying that this command
correct i'm not saying that this command is wrong but why are we not writing
is wrong but why are we not writing search context driver is equal to new
search context driver is equal to new chrome driver and why are we writing web
chrome driver and why are we writing web driver driver is equal to new chrome
driver driver is equal to new chrome driver
driver the reason behind this is refer add this
the reason behind this is refer add this diagram again
diagram again here i have uh told before that the
here i have uh told before that the search context interface contains only
search context interface contains only two methods that is the find element and
two methods that is the find element and the fine elements
the fine elements so if we are writing search context
so if we are writing search context driver 1 is equal to new chrome driver
driver 1 is equal to new chrome driver it will only have
it will only have two abstract classes or sorry two
two abstract classes or sorry two abstract methods that is the
abstract methods that is the find element and the fine elements
find element and the fine elements whereas if i'm writing web driver it has
whereas if i'm writing web driver it has all those methods like the fine element
all those methods like the fine element and the fine elements also and all the
and the fine elements also and all the web driver methods as well so that is
web driver methods as well so that is the reason why we are writing web driver
the reason why we are writing web driver driver is equal to new chrome driver
driver is equal to new chrome driver okay
okay so now the next question that you must
so now the next question that you must be thinking is okay we are fine with the
be thinking is okay we are fine with the search context we are not uh there's no
search context we are not uh there's no advantage in writing search context
advantage in writing search context because it will have only two methods
because it will have only two methods included in it uh that is a find element
included in it uh that is a find element in the find elements so why not remote
in the find elements so why not remote why not remote web driver
why not remote web driver like we can write remote web driver
like we can write remote web driver driver
driver sequel to new
sequel to new chrome driver this is also possible
chrome driver this is also possible but the reason behind why we're not
but the reason behind why we're not writing remote webdriver is because the
writing remote webdriver is because the remote webdriver mechanism the
remote webdriver mechanism the architecture of the remote web driver is
architecture of the remote web driver is very different from the web driver here
very different from the web driver here there are two reasons okay if we want to
there are two reasons okay if we want to use this approach the remote web driver
use this approach the remote web driver driver 3 is equal to new chrome driver
driver 3 is equal to new chrome driver if you're using this approach
if you're using this approach then
then this approach is only accessible when we
this approach is only accessible when we want to access in remote location see
want to access in remote location see here the remote web driver works very
here the remote web driver works very different from the web driver and it
different from the web driver and it also the remote web driver is a class
also the remote web driver is a class always remember there's a difference
always remember there's a difference between a class and an interface okay
between a class and an interface okay so class
so class and it contains methods which
and it contains methods which shows that which what action is to be
shows that which what action is to be performed that is remote web driver
performed that is remote web driver whereas interface it contains the
whereas interface it contains the abstract method so the remote web driver
abstract method so the remote web driver is not serving as advantages as the web
is not serving as advantages as the web driver that we have included over here
driver that we have included over here so it is the best practice is to include
so it is the best practice is to include the web driver driver is equal to new
the web driver driver is equal to new chrome driver
chrome driver okay so i'll delete this
okay so i'll delete this command
command and yeah through system.set property
and yeah through system.set property uh we have a key value we have entered
uh we have a key value we have entered the string value over here that is the
the string value over here that is the webdriver.chrome.driver
webdriver.chrome.driver and here we have entered the path of our
and here we have entered the path of our executable chrome driver next we have
executable chrome driver next we have written web driver driver is equal to
written web driver driver is equal to new chrome driver
new chrome driver through these two steps
through these two steps the chrome browser is launched now
the chrome browser is launched now remember these two steps are common for
remember these two steps are common for all the test cases we are going to write
all the test cases we are going to write because in every test case we are going
because in every test case we are going to launch a browser so these two steps
to launch a browser so these two steps are going to be similar
are going to be similar okay
okay so the next test case the next test case
so the next test case the next test case that we have is
that we have is navigate to the
navigate to the url okay
url okay how are you going to do that now we have
how are you going to do that now we have driver as a reference variable we're
driver as a reference variable we're going to write driver dot
going to write driver dot get
get and we're going to include the
and we're going to include the site where we want to navigate that is
site where we want to navigate that is www.google.com
this is the site i want to navigate to i'm going to run this command
the chrome browser is launched but it has not navigated to
it has not navigated to the url why let's see
so here it says chrome browser chrome driver was started successfully and here
driver was started successfully and here it says
it says invalid argument exception there is
invalid argument exception there is invalid argument why
invalid argument why let me tell you here when we write the
let me tell you here when we write the url you need to write the complete url
url you need to write the complete url which includes https
which includes https colon and slash
so our chrome browser is launched and here it is it is navigated to the url
here it is it is navigated to the url that is the
that is the google.com okay
google.com okay i'll just close this
i'll just close this i'll close this as well okay
i'll close this as well okay so now you have understood to navigate
so now you have understood to navigate your url we will write driver dot get
your url we will write driver dot get the get command is used to navigate to
the get command is used to navigate to the url okay
is to close the browser
how are we going to do that we're going to simply write driver
to simply write driver dot
dot close
the close command is used to close the browser
save it and run
so your our chrome browser is launched and it is navigated to the url and it is
and it is navigated to the url and it is closed
closed see it happens very fast
see it happens very fast but uh yeah this is the process like we
but uh yeah this is the process like we have launched the chrome browser we have
have launched the chrome browser we have navigated to the url and we have closed
navigated to the url and we have closed the browser
the browser to navigate the url we are using the get
to navigate the url we are using the get command and to close the browser we are
command and to close the browser we are using the close command
using the close command so these were the steps to launch the
so these were the steps to launch the browser to navigate to the url and to
browser to navigate to the url and to close the browser
close the browser now let's execute the
now let's execute the second test set
second test set which has the firefox browser which in
which has the firefox browser which in which we have to launch the firefox
which we have to launch the firefox browser so i'll comment all these
browser so i'll comment all these and we're going to
and we're going to launch the firefox first okay there is
launch the firefox first okay there is no harm if we write both the browsers
no harm if we write both the browsers there's no harm it will execute the
there's no harm it will execute the chrome browser first and then it will
chrome browser first and then it will execute the firefox browser first we
execute the firefox browser first we will do that also but first let us
will do that also but first let us execute this particularly okay
execute this particularly okay so in the next set of test cases
so in the next set of test cases here it is we have open the firefox
here it is we have open the firefox browser navigate to the url and close
browser navigate to the url and close the browser the only difference is that
the browser the only difference is that we are working with the firefox browser
we are working with the firefox browser over here okay and over here we were
over here okay and over here we were working with the chrome browser
working with the chrome browser so let's start
so let's start first thing
first thing the first test case which says that we
the first test case which says that we have to open the
have to open the firefox browser
firefox browser okay so how we're going to do that
okay so how we're going to do that obviously we're going to write system
obviously we're going to write system dot
dot set property
set property which is having two string values one is
which is having two string values one is key and one is the
key and one is the value okay so over here you can see
value okay so over here you can see over here
over here the key value is webdriver.chrome.driver
the key value is webdriver.chrome.driver so here it's going to be a web driver
so here it's going to be a web driver dot getco
dot getco gecko is the driver name for the firefox
gecko is the driver name for the firefox browser
browser dot
dot driver
driver okay
okay this is the key
now we will enter the value how we're going to do that we're going to go to
going to do that we're going to go to the path where our
the path where our firefox
firefox driver is saved
driver is saved here it is
here it is i'm going to copy this path
i'm going to simply paste it over here we will
we will change the slashes
change the slashes and we are going to include the
and we are going to include the file name
file name so our file name is getco driver
so our file name is getco driver gecko
gecko driver
driver dot exe
dot exe okay
okay and
and next command our next command is that
next command our next command is that we're going to create an object of
we're going to create an object of firefox first and how we're going to
firefox first and how we're going to refer it we are going to refer it by the
refer it we are going to refer it by the web driver interface
web driver interface web driver
web driver driver
driver is equal to new firefox
is equal to new firefox okay
okay next
next we need to navigate to the url how we're
we need to navigate to the url how we're gonna do that
gonna do that navigate
navigate to
to the url
the url we're gonna simply write
we're gonna simply write driver
driver dot get
https we need to write https colon
colon www.google.com
okay now the third command
now the third command is to
is to close the
close the browser how we're gonna do it we simply
browser how we're gonna do it we simply write driver
write driver dot close
dot close okay so let's
okay so let's launch it
launch it let's run this program we'll click on
let's run this program we'll click on this
and here it is our firefox is launched it is navigated and
it is navigated and it's closed yes
it's closed yes so as i said there's no harm like simply
so as i said there's no harm like simply i will
i will uncomment all
these i'll name this as driver one
name this as driver one driver one and driver one
driver one and driver one okay so let's execute this
okay so let's execute this statement it will open the chrome driver
statement it will open the chrome driver first
yes it is opening the chrome driver first it is navigating and it is closing
first it is navigating and it is closing now our firefox will be opened yes
now our firefox will be opened yes it is navigating and it is
it is navigating and it is closed so there is no harm if you are
closed so there is no harm if you are including two browsers in one program
including two browsers in one program there is no harm in that okay just
there is no harm in that okay just change the reference variable your i
change the reference variable your i have changed the reference variable to
have changed the reference variable to driver 1 and driver
driver 1 and driver now since we have executed these two
now since we have executed these two sets of test cases
sets of test cases now let me explain you this command now
now let me explain you this command now here we have written web driver driver
here we have written web driver driver is equal to new firefox driver
is equal to new firefox driver we can also write
we can also write firefox
firefox driver
driver dr1 is equal to new
dr1 is equal to new firefox driver
firefox driver this command
this command is also valid okay it's there's no harm
is also valid okay it's there's no harm in writing firefox driver dr1 is equal
in writing firefox driver dr1 is equal to new firefox driver
to new firefox driver but what are the disadvantages behind
but what are the disadvantages behind this
this statement i'll tell you
statement i'll tell you now see when you're working in an
now see when you're working in an organization you are working
organization you are working with many people you will be having at
with many people you will be having at least 500 number of test case cases and
least 500 number of test case cases and out of which 250 test cases are need to
out of which 250 test cases are need to be automated so there are large number
be automated so there are large number of test cases which are need to be
of test cases which are need to be automated in that you will be supporting
automated in that you will be supporting the cross browser testing
the cross browser testing so
so you have to simultaneously uh
you have to simultaneously uh run a multiple browsers at the same time
run a multiple browsers at the same time okay and then a large number of test
okay and then a large number of test cases now see the advantage behind
cases now see the advantage behind writing webdriver driver is equal to new
writing webdriver driver is equal to new firefox driver your you are not stick to
firefox driver your you are not stick to one browser
one browser you can
you can execute multiple browsers this way but
execute multiple browsers this way but whereas if we write firefox driver
whereas if we write firefox driver driver one is equal to a new firefox
driver one is equal to a new firefox driver here we are stick to one driver
driver here we are stick to one driver it is um we are specific towards the
it is um we are specific towards the driver that is the firefox driver here
driver that is the firefox driver here if you want to change to chrome driver
if you want to change to chrome driver it will be you have to write chrome
it will be you have to write chrome driver
dr2 is equal to new
new this is what you have to write if you
this is what you have to write if you want to change to chrome driver and you
want to change to chrome driver and you have to
have to comment this line and even have you have
comment this line and even have you have to change there will be many other
to change there will be many other changes also in the program because of a
changes also in the program because of a driver okay so this thing is very
driver okay so this thing is very harmful it is not a good practice of
harmful it is not a good practice of writing this command that is the firefox
writing this command that is the firefox driver
driver driver is equal to new firefox driver
driver is equal to new firefox driver whereas when if you if you're working
whereas when if you if you're working with this and there is a situation where
with this and there is a situation where you have to change to chrome driver you
you have to change to chrome driver you have to simply just change over your
have to simply just change over your chrome driver
chrome driver you will just write chrome driver
you will just write chrome driver and your entire program will be
and your entire program will be launched through a chrome driver okay so
launched through a chrome driver okay so this is the difference between the web
this is the difference between the web driver driver is equal to new chrome
driver driver is equal to new chrome driver and the chrome driver driver is
driver and the chrome driver driver is equal to new chrome driver these are the
equal to new chrome driver these are the problems that we are facing if you are
problems that we are facing if you are writing chrome driver driver is equal to
writing chrome driver driver is equal to new chrome driver that is the program is
new chrome driver that is the program is specific towards the chrome driver
specific towards the chrome driver whereas if you are writing web driver
whereas if you are writing web driver driver is equal to new chrome driver it
driver is equal to new chrome driver it is not specific to us a particular
is not specific to us a particular browser okay
browser okay so let's first rely revise what have we
so let's first rely revise what have we uh understood in this tutorial
uh understood in this tutorial so what did we learn the first thing
so what did we learn the first thing that we learnt is to launch the browser
that we learnt is to launch the browser in case of chrome browser how did we do
in case of chrome browser how did we do first we uh
first we uh set the property to a system class that
set the property to a system class that is a system.set property in which we are
is a system.set property in which we are having two string
having two string we need to enter two string values that
we need to enter two string values that is the string key and the string value
is the string key and the string value in case of chrome driver the string key
in case of chrome driver the string key is the webdriver chrome driver whereas
is the webdriver chrome driver whereas the string value will be the path where
the string value will be the path where our executable file is saved
our executable file is saved the next statement is that we're going
the next statement is that we're going to write web driver driver is equal to
to write web driver driver is equal to new chrome driver through these commands
new chrome driver through these commands it will launch the chrome browser
it will launch the chrome browser now in case of firefox browser same we
now in case of firefox browser same we are going to write system.set property
are going to write system.set property but the key value will change that is
but the key value will change that is the webdriver.getcode.driver
the webdriver.getcode.driver and also the path where our firefox
and also the path where our firefox driver is placed that will also change
driver is placed that will also change okay then the next command will be web
okay then the next command will be web driver driver is equal to new firefox
driver driver is equal to new firefox driver through this command we are
driver through this command we are launching our firefox browser
launching our firefox browser next we learned how to navigate to a
next we learned how to navigate to a particular url simply we will use driver
particular url simply we will use driver dot get command the get command is used
dot get command the get command is used to navigate to a particular url we have
to navigate to a particular url we have to include the https uh all the website
to include the https uh all the website any any url you are entering over here
any any url you are entering over here you have to entire the you have to enter
you have to entire the you have to enter the full url the entire url including
the full url the entire url including the https okay
the https okay then to close the browser we learned how
then to close the browser we learned how to close the browser that is we are
to close the browser that is we are using the close command that is a
using the close command that is a driver.close command
driver.close command so the next thing
so the next thing the next thing that we learned is about
the next thing that we learned is about the hierarchy of the classes and the
the hierarchy of the classes and the interfaces
interfaces that is we learned first thing about the
that is we learned first thing about the search context it is a super interface
search context it is a super interface of the web driver and it has only two
of the web driver and it has only two methods that is the fine element and the
methods that is the fine element and the find elements
find elements next we learned that the web driver is
next we learned that the web driver is an interface which extends the search
an interface which extends the search context interface and the web driver has
context interface and the web driver has methods like the get method the get
methods like the get method the get title get current url close quit etc
title get current url close quit etc that has many methods and also it
that has many methods and also it has the nested interfaces also then the
has the nested interfaces also then the remote web driver is a fully implemented
remote web driver is a fully implemented class which implements the web driver
class which implements the web driver interface
interface okay
okay then we have the chrome driver the
then we have the chrome driver the internet explorer driver the firefox
internet explorer driver the firefox driver opera safari driver all these are
driver opera safari driver all these are child classes of the remote webdriver
child classes of the remote webdriver class and they provide the browser
class and they provide the browser specific implementation of the selenium
specific implementation of the selenium webdriver
webdriver so these are the hierarchy of the
so these are the hierarchy of the classes and the interfaces of the
classes and the interfaces of the selenium webdriver
selenium webdriver next next we learned that what are the
next next we learned that what are the this is this this ppt shows that what
this is this this ppt shows that what are the valid statements that we can
are the valid statements that we can write through uh creating an object of
write through uh creating an object of chrome driver and how can we refer it
chrome driver and how can we refer it now writing web driver driver is equal
now writing web driver driver is equal to new web driver this command is wrong
to new web driver this command is wrong okay this command is wrong
okay this command is wrong we can write web driver driver is equal
we can write web driver driver is equal to new chrome driver new firefox driver
to new chrome driver new firefox driver new internet explorer driver this is the
new internet explorer driver this is the best practice in industry level we use
best practice in industry level we use the web driver driver is equal to new
the web driver driver is equal to new chrome driver this command is frequently
chrome driver this command is frequently cut this command is only used because uh
cut this command is only used because uh writing this command firefox driver
writing this command firefox driver through this it is the program the
through this it is the program the script that you're writing is specific
script that you're writing is specific towards a firefox only it is launching
towards a firefox only it is launching it will launch only the firefox browser
it will launch only the firefox browser whereas over here also it will launch
whereas over here also it will launch only the firefox driver but there's a
only the firefox driver but there's a situation where you have to change the
situation where you have to change the driver they will they might say that the
driver they will they might say that the company says that you have to launch the
company says that you have to launch the chrome browser
chrome browser launch the entire test script in the
launch the entire test script in the chrome browser so what you're going to
chrome browser so what you're going to do is you just have to simply change
do is you just have to simply change over here to chrome driver and you're
over here to chrome driver and you're done but whereas if you're uh writing
done but whereas if you're uh writing firefox driver you have to change the
firefox driver you have to change the entire statement and there will be other
entire statement and there will be other statements also that you have to change
statements also that you have to change okay
okay so the best practice is the web driver
so the best practice is the web driver practice web driver driver is equal to
practice web driver driver is equal to new firefox driver but whereas if you
new firefox driver but whereas if you write chrome driver driver is equal to
write chrome driver driver is equal to new chrome driver there's no harm in it
new chrome driver there's no harm in it but the best practice is to write the
but the best practice is to write the web driver
web driver so this is all for today
so this is all for today so in this tutorial we will understand
so in this tutorial we will understand what are web elements what are the
what are web elements what are the different types of web elements we will
different types of web elements we will understand the locators and its types
understand the locators and its types also we will understand the difference
also we will understand the difference between find elements and find element
between find elements and find element method
method so let's get started
first thing what is web element now anything that is present on the web
now anything that is present on the web page is called as a web element for
page is called as a web element for example the text box is a drop down menu
example the text box is a drop down menu the radio button anything that is
the radio button anything that is present on the web page is known as a
present on the web page is known as a web element
web element let me show you this site for example
for example this is the web page now anything that is present on this web
anything that is present on this web page anything that is this search bar
page anything that is this search bar these uh
these uh my account link this more link this cart
my account link this more link this cart link the search icon anything that is
link the search icon anything that is present over here is a web element we
present over here is a web element we have to inspect all these elements like
have to inspect all these elements like over here if you want to send any
over here if you want to send any command if you want to send any text
command if you want to send any text message on the search bar how are we
message on the search bar how are we going to do that we're going to inspect
going to do that we're going to inspect the elements so all these are known as
the elements so all these are known as web elements
now web elements are basically of two types one is single element the second
types one is single element the second is the group elements
is the group elements now single element
now single element this is the registration page here you
this is the registration page here you can see
can see here you can see these text boxes right
here you can see these text boxes right so these are single elements why because
so these are single elements why because of we can easily find out a locator to
of we can easily find out a locator to work with this for example we can find
work with this for example we can find it through id we can find out through
it through id we can find out through name so these are the different types of
name so these are the different types of locators that will be used to uh inspect
locators that will be used to uh inspect these elements these text boxes this
these elements these text boxes this radio button
radio button but
but i'm explaining here what are the
i'm explaining here what are the different types of web elements so there
different types of web elements so there are two one is the single element the
are two one is the single element the second is the group element single
second is the group element single elements are the text boxes because we
elements are the text boxes because we can identify them very easily through
can identify them very easily through locators through name through class name
locators through name through class name whereas the drop down menu they are
whereas the drop down menu they are known as group elements because
known as group elements because here to identify the drop down menu we
here to identify the drop down menu we will use a locator as well as that we
will use a locator as well as that we will use a combination of a value or
will use a combination of a value or index property now what is this value or
index property now what is this value or index property when we understand how to
index property when we understand how to uh inspect the drop down menu at that
uh inspect the drop down menu at that time we will come to know that what are
time we will come to know that what are the different types of
the different types of commands that is used to inspect the
commands that is used to inspect the drop down menu so there is a reason why
drop down menu so there is a reason why it is called as a group element
it is called as a group element so next we have locators now what are
so next we have locators now what are locators locators are the way to
locators locators are the way to identify and web element
identify and web element anything that is present on a web page
anything that is present on a web page is called as a web element right so how
is called as a web element right so how do we identify it for example
do we identify it for example here you can see right this search box
here you can see right this search box how will you identify the search box how
how will you identify the search box how will you send commands to the search box
will you send commands to the search box how will you uh click on this icon on
how will you uh click on this icon on the search icon how will you do that for
the search icon how will you do that for that you need to inspect these elements
that you need to inspect these elements for that you need to locate these
for that you need to locate these elements so how we gonna do that simply
elements so how we gonna do that simply just place your cursor on this element
just place your cursor on this element or whichever element you want to inspect
or whichever element you want to inspect just right click it
just right click it and click on inspect
and click on inspect and here you can see
and here you can see see i'm
see i'm actually placing my mouse on this syntax
actually placing my mouse on this syntax of search button of this search box and
of search button of this search box and it is highlighting here you can see
it is highlighting here you can see right it is highlighting
right it is highlighting so this is the way you can inspect your
so this is the way you can inspect your web element and through these locators
web element and through these locators we will
we will inspect the element for example here you
inspect the element for example here you can see input this input is your tag
can see input this input is your tag name it is an element
name it is an element your input has many attributes like we
your input has many attributes like we have class we have type we have name we
have class we have type we have name we have title so these are the different
have title so these are the different attributes of input tag so we will be
attributes of input tag so we will be using these attributes as locators to
using these attributes as locators to locate these web elements to inspect
locate these web elements to inspect these web elements okay
these web elements okay so now what are locators locators are a
so now what are locators locators are a way to identify a html element on a web
way to identify a html element on a web page
page as we
as we just saw right now now there are
just saw right now now there are different types of locators one is the
different types of locators one is the locator the second is the customized
locator the second is the customized locator under locator we have the id we
locator under locator we have the id we have the name we have the link text and
have the name we have the link text and the partial link text we have the tag
the partial link text we have the tag name we have the class name whereas in
name we have the class name whereas in customized locators we have the css
customized locators we have the css selector and the x bar now this xpath is
selector and the x bar now this xpath is one of the most important locators and
one of the most important locators and it is frequently used by many
it is frequently used by many automation testers because it is one of
automation testers because it is one of the most easiest thing and uh we will be
the most easiest thing and uh we will be using a different uh plugin for this
using a different uh plugin for this expert that is called the crow path
expert that is called the crow path plugin so choosing xpath as a locator
plugin so choosing xpath as a locator will be one of the most easiest locator
will be one of the most easiest locator yeah even though id name and all these
yeah even though id name and all these are easiest but most of the time peop
are easiest but most of the time peop automation testers they prefer the xpath
automation testers they prefer the xpath locator
locator okay so we will do that at the end
okay so we will do that at the end because there are many uh technical
because there are many uh technical things also in this it is
things also in this it is a little hard to understand before that
a little hard to understand before that we will understand what is id name link
we will understand what is id name link text partial link text tag name class
text partial link text tag name class name and css selector and you will have
name and css selector and you will have a command on this we will
a command on this we will practically implement also this
practically implement also this okay so locating by id
okay so locating by id now uh before proceeding i would
now uh before proceeding i would recommend you to
recommend you to have a basic knowledge about the html
have a basic knowledge about the html which will be very beneficial for you
which will be very beneficial for you because we are automating the web pages
because we are automating the web pages over here and a web page is made up of
over here and a web page is made up of html css javascript languages so your
html css javascript languages so your html and css will play a lot of role
html and css will play a lot of role over here
over here in locating the web elements just the
in locating the web elements just the basic knowledge and then it's fine
basic knowledge and then it's fine okay
okay so now locating by id
so now locating by id now id they are unique for each element
now id they are unique for each element the id value that we have right is
the id value that we have right is always unique for each element and it is
always unique for each element and it is one of the most common way of
one of the most common way of locating an element
locating an element and the id are supposed to be unique on
and the id are supposed to be unique on a page
a page and that is the reason why id are the
and that is the reason why id are the most reliable locators like in form of
most reliable locators like in form of priorities whenever the automation
priorities whenever the automation tester tests the application
tester tests the application the first thing that they will do is
the first thing that they will do is they will try to automate the web
they will try to automate the web element through
element through id
id because uh id the value of id is always
because uh id the value of id is always unique for each element so that is the
unique for each element so that is the reason why id is one of the most
reason why id is one of the most reliable locator and the fastest and the
reliable locator and the fastest and the safest locators out of all the locators
safest locators out of all the locators okay
okay now let us assume this is your text box
now let us assume this is your text box email address and you want to send some
email address and you want to send some value over here you want to automate
value over here you want to automate this field okay you want to inspect this
this field okay you want to inspect this field you want to send some value over
field you want to send some value over your how you're going to do that and
your how you're going to do that and this is the html syntax that you have
this is the html syntax that you have for this text box
for this text box so how will we locate this element by id
so how will we locate this element by id we will simply write driver dot find
we will simply write driver dot find element
element here i am using find element and not
here i am using find element and not find elements okay
find elements okay driver dot find element by dot id
driver dot find element by dot id and here when you inspect this element
and here when you inspect this element when you uh right click and inspect on
when you uh right click and inspect on this element here you will get the
this element here you will get the syntax right over your id is equal to
syntax right over your id is equal to email you will place this value over
email you will place this value over here now see whatever value you enter
here now see whatever value you enter here is case sensitive okay whatever is
here is case sensitive okay whatever is written over here you have to write it
written over here you have to write it over here the same way like over here
over here the same way like over here the email is written in small letters
the email is written in small letters you need to enter your email in small
you need to enter your email in small letters only it's case sensitive okay
letters only it's case sensitive okay then i will
then i will send a form command this is the send key
send a form command this is the send key command over use this is a form control
command over use this is a form control which is used over here to send a
which is used over here to send a particular text to this field what i'm
particular text to this field what i'm doing is send keys abc at the right
doing is send keys abc at the right gmail.com right so i'm sending this
gmail.com right so i'm sending this email id that is abc at the gmail.com in
email id that is abc at the gmail.com in this text field the text field which is
this text field the text field which is located over here this email
located over here this email so you get it i'm writing driver dot
so you get it i'm writing driver dot find element by dot id email which i
find element by dot id email which i found it over here in the syntax
found it over here in the syntax dot send keys abc at the rate gmail.com
dot send keys abc at the rate gmail.com so this is the way how i'm going to
so this is the way how i'm going to locate the id see we're going to
locate the id see we're going to implement it also
implement it also first just understand this command
first just understand this command okay
okay the next one
the next one locating by name the next locator is
locating by name the next locator is name okay
name okay now here
now here same same thing just assume you have a
same same thing just assume you have a text box which is name uh which is of
text box which is name uh which is of email address and this is the
email address and this is the syntax of it so how we gonna look it by
syntax of it so how we gonna look it by name it's the same same as id but the
name it's the same same as id but the only difference between name and id is
only difference between name and id is that
that name locator
name locator are not unique for a page like i said
are not unique for a page like i said for id for each element the id value is
for id for each element the id value is unique whereas for name it's not that
unique whereas for name it's not that okay
okay that is the difference between the id
that is the difference between the id and the name
and the name so over here you can see right name is
so over here you can see right name is equal to from similarly we will write
equal to from similarly we will write driver dot find element
driver dot find element by dot name
by dot name from
from dot send keys abc at the rate gmail.com
dot send keys abc at the rate gmail.com so this is the command which i will use
so this is the command which i will use to locate by name locator
now let's implement this uh practically i'll just open my intellij idea ide
so now i'll create a new java class simply uh i'm having this project name
simply uh i'm having this project name selenium and i'll create a new java
selenium and i'll create a new java class i'll name it as
class i'll name it as selenium
now here you can see this web page now we will be automating this web page
we will be automating this web page so the task that we have for today is
so the task that we have for today is here you can see the search bar
here you can see the search bar so we will be automating this search bar
so we will be automating this search bar so how we gonna do that we simply gonna
so how we gonna do that we simply gonna click on the search bar and click on
click on the search bar and click on inspect
inspect and here you can see
and here you can see as my mouse is on the syntax and you can
as my mouse is on the syntax and you can see that the search box is
see that the search box is highlighted
highlighted okay here we have different attributes
okay here we have different attributes like the class we have the type we have
like the class we have the type we have id we have name so we will be using
id we have name so we will be using these attributes to locate this search
these attributes to locate this search element one by one okay
element one by one okay so let's do it
so let's do it now open your intelligent idea id and
now open your intelligent idea id and create a new class i created a new class
create a new class i created a new class in
in my selenium project that is the selenium
my selenium project that is the selenium tutorials too and
tutorials too and in the previous tutorial i explained how
in the previous tutorial i explained how to launch a browser we will be launching
to launch a browser we will be launching the chrome browser so here i have
the chrome browser so here i have written the two commands that were used
written the two commands that were used in launching the chrome browser that is
in launching the chrome browser that is the system dot set property here we have
the system dot set property here we have to enter the key value that is the
to enter the key value that is the webdriver.chrome.driver
webdriver.chrome.driver and the uh path of the executable file
and the uh path of the executable file that is the chrome driver executable
that is the chrome driver executable file
file next we had written that the web driver
next we had written that the web driver driver is equal to new chrome driver so
driver is equal to new chrome driver so these two commands are used to launch
these two commands are used to launch the chrome browser so let's run this
okay so your our chrome browser is launched now what i want to do is i want
launched now what i want to do is i want to maximize this chrome browser that is
to maximize this chrome browser that is my chrome browser is minimized right now
my chrome browser is minimized right now this is what i want
this is what i want so how am i going to do that
so how am i going to do that i'll simply write
i'll write driver dot manage
dot manage dot window
dot window dot maximize
dot maximize so this command will maximize the chrome
so this command will maximize the chrome browser now let's see
browser now let's see let's run
so here you can see my chrome browser got maximized okay
as i said we are going to locate this search box through id and by name okay
search box through id and by name okay locators so let's do it by id first
let's do it by id locator so first
so first okay sorry uh just before that we have
okay sorry uh just before that we have to navigate to the
to navigate to the uh url right so first we will
uh url right so first we will navigate to the
navigate to the url
url we're gonna write
we're gonna write driver dot
driver dot get
get gonna enter this
gonna enter this url
and yeah okay
okay so yeah first we launched the chrome
so yeah first we launched the chrome browser we maximized the chrome browser
browser we maximized the chrome browser then we navigated to the url let's check
then we navigated to the url let's check it first
it's launched the chrome browser is launched maximized
launched maximized and it is navigated to this url
and it is navigated to this url so i'll just close this
so i'll just close this now
now as i said i want to
as i said i want to locate this search box this search box
locate this search box this search box through id
through id now here same i'll just place my command
now here same i'll just place my command click on inspect and your this
click on inspect and your this syntax here you can see right
syntax here you can see right this syntax here you can see id is equal
this syntax here you can see id is equal to search underscore query underscore
to search underscore query underscore top
top so this value will be used to locate
so this value will be used to locate this search box now how am i going to do
this search box now how am i going to do that just check it out first
that just check it out first okay
okay so what i'm going to do is i'm going to
so what i'm going to do is i'm going to write driver
write driver dot
dot find element
find element let's find element and not find elements
let's find element and not find elements okay fine element
okay fine element i'm gonna write by
i'm gonna write by dot
dot see here you can see it's by dot tag
see here you can see it's by dot tag name id class name css selector so i'm
name id class name css selector so i'm using id
using id id
id and then i will here
and then i will here insert the value of id that is given
insert the value of id that is given over here simply just double click on it
over here simply just double click on it copy it
copy it and paste it over here okay it is case
and paste it over here okay it is case sensitive so play uh paste the same
sensitive so play uh paste the same thing the this this thing this value
thing the this this thing this value should be same
should be same as
as the id that is given in that syntax okay
the id that is given in that syntax okay now what i want to do is i want to send
now what i want to do is i want to send some command to it so i'll write send
some command to it so i'll write send keys
keys and i'll simply just type
and i'll simply just type i want to send
i want to send t-shirts
and here you can see you could see it's your it's written t-shirts right we
your it's written t-shirts right we haven't
haven't inspected this element this search bar
inspected this element this search bar and that's why it's not clicking on this
and that's why it's not clicking on this okay we will do that later
okay we will do that later so now
so now this is the first way of writing driver
this is the first way of writing driver dot find element by id and dot sign keys
dot find element by id and dot sign keys okay the second method that you can
okay the second method that you can write this command is
write this command is let me comment this so i can write
let me comment this so i can write driver
driver similarly just the same thing
similarly just the same thing but
but i'll write it in a different way find
i'll write it in a different way find element i'll write by dot id
okay that's it now what i'm going to do is
that's it now what i'm going to do is i'm going to store this
i'm going to store this in a variable i will name it as
in a variable i will name it as search
search is equal to driver dot fine element by
is equal to driver dot fine element by dot id
dot id now what i'm doing i'm locating a web
now what i'm doing i'm locating a web element right in java usually when we
element right in java usually when we write we write it as int a is equal to
write we write it as int a is equal to 10 right then we write
10 right then we write float
float b is equal to 10.2 so you're giving some
b is equal to 10.2 so you're giving some data type to your a and b variables
data type to your a and b variables right so here also we will
right so here also we will this search element
this search element so here also we will write something
so here also we will write something right so what you're going to do that so
right so what you're going to do that so what you're going to write
what you're going to write simply here you see this search
simply here you see this search underscore queries underscore talk what
underscore queries underscore talk what is this we are locating a web element
is this we are locating a web element right
right so we are finding a web element on a web
so we are finding a web element on a web page so this search variable will be of
page so this search variable will be of what type it will be of web element type
what type it will be of web element type so web element search is equal to driver
so web element search is equal to driver dot find element by dot id search
dot find element by dot id search underscore query underscore talk
underscore query underscore talk okay
okay now over here you could see i had
now over here you could see i had written dots and key so simply what i'll
written dots and key so simply what i'll do is i'll write
do is i'll write search
search dot
dot send keys and i'm gonna write
send keys and i'm gonna write t-shirts
t-shirts okay
okay so let's run this command this is the
so let's run this command this is the second way of writing this
second way of writing this one line command
one line command you can write it this way or you can
you can write it this way or you can write it this way depends on your
it's maximized is navigated to this url
and here it is you can see it's t-shirt here the value is sent
here the value is sent okay so i'll just close this
okay so i'll just close this and close this also
and close this also okay so i'll just comment this
for now this method
is better okay
okay next we will do it by
next we will do it by name
name we will locate the search box by
we will locate the search box by name
name okay so how we gonna do that
okay so how we gonna do that again we're gonna write
again we're gonna write driver
driver dot find element
dot find element by
by dot
dot name
we have the value of name just double click it
click it copy it
copy it paste it over here
paste it over here and write
and write dot send keys i'll write
chrome browser is launched it's maximized
maximized it is navigated to this url
and here you can see
here you can see okay wait a minute
okay wait a minute okay i didn't
okay i didn't comment this let me comment this
comment this let me comment this okay
it's maximized it's navigated to this url
and here you can see it's shorts okay
okay so i'll just close this
so i'll just close this now we have understood how do we locate
now we have understood how do we locate by id and how do we look it by name
by id and how do we look it by name similarly here you can see the
similarly here you can see the your the same way the same way you can
your the same way the same way you can write it by name also there's nothing
write it by name also there's nothing different in it but this is the most
different in it but this is the most precise way you just write it in your in
precise way you just write it in your in one line here you have to write in two
one line here you have to write in two lines is the same thing
lines is the same thing so i prefer this one so it's up to you
so i prefer this one so it's up to you which one do you prefer there's no harm
which one do you prefer there's no harm in writing
in writing either of the way okay
either of the way okay so we have learnt by id we have learned
so we have learnt by id we have learned by name
by name next we have locating by link text and
next we have locating by link text and partial link text now what is link text
partial link text now what is link text and partial link text
and partial link text see
see whenever we have links in our pages okay
whenever we have links in our pages okay like there's a web page and there are
like there's a web page and there are links involved in this in that case we
links involved in this in that case we have the link text and the partial link
have the link text and the partial link text
now link text and partial link text both are different they are not the same but
are different they are not the same but partial link text is not mostly used by
partial link text is not mostly used by the automation testers
the automation testers link text is mostly used by the testers
link text is mostly used by the testers because this is the most precise way of
because this is the most precise way of automating or clicking a link for
automating or clicking a link for example like suppose let me show you
example like suppose let me show you here this page you can see right now
here this page you can see right now your woman
your woman i have dresses
i have dresses now there are various dresses over here
now there are various dresses over here so if i want to click on this link here
so if i want to click on this link here you can see this link
you can see this link so if i want to click on this like how
so if i want to click on this like how am i going to do i'm just simply going
am i going to do i'm just simply going to click inspect
to click inspect and here you can see this you can see
and here you can see this you can see there's an anchor tag over here
there's an anchor tag over here so this anchor tag is used for links in
so this anchor tag is used for links in html okay now here you can see is there
html okay now here you can see is there any class is there any name or id
any class is there any name or id attribute used over here no right so how
attribute used over here no right so how will you identify this element how will
will you identify this element how will you inspect this element we will inspect
you inspect this element we will inspect this element through link text that is
this element through link text that is the link text which is written over here
the link text which is written over here you can see women a line multi-color
you can see women a line multi-color dress you can see this uh text written
dress you can see this uh text written over here right we're gonna inspect
over here right we're gonna inspect through this text this is the link text
through this text this is the link text that is given over here
that is given over here and the a class which denotes the anchor
and the a class which denotes the anchor class
class uh
uh which is used for links in html okay so
which is used for links in html okay so for clicking the links in selenium we
for clicking the links in selenium we will be using the link text locator
so how are we going to locate this element through link text or partial
element through link text or partial link text now for example here we have
link text now for example here we have various links like the printed dress the
various links like the printed dress the printed summer dress and this is the
printed summer dress and this is the syntax of this okay
syntax of this okay so
so it is a syntax of sprinted summer dress
it is a syntax of sprinted summer dress so how we're going to click on this
so how we're going to click on this printed summer dress how we're going to
printed summer dress how we're going to click on this link
click on this link for that
for that we will be using i'll be explaining link
we will be using i'll be explaining link text first we'll write driver dot find
text first we'll write driver dot find element by dot link text
element by dot link text printed summer dress here you can see
printed summer dress here you can see this is printed summer dress this link
this is printed summer dress this link text is used to identify this element
text is used to identify this element here you can see there is printed summer
here you can see there is printed summer dress this printed summer dress right
dress this printed summer dress right this text is used to identify this
this text is used to identify this element that is the printed summer dress
element that is the printed summer dress okay so i just simply write printed some
okay so i just simply write printed some address this is case sensitive to cited
address this is case sensitive to cited the same way and dot click again before
the same way and dot click again before we were writing send keys right that is
we were writing send keys right that is the form command this is also form
the form command this is also form command which is used to click a
command which is used to click a specific element or to click a specific
specific element or to click a specific link so what operation i need to perform
link so what operation i need to perform over here i want to click this element
over here i want to click this element right print it somewhere else so i'm
right print it somewhere else so i'm going to write dot click
going to write dot click similarly for partial link text what you
similarly for partial link text what you do you partially write the text like
do you partially write the text like over here we have the printed summer
over here we have the printed summer dress we'll just write some address
dress we'll just write some address still it will detect this printed sum
still it will detect this printed sum address and it will click at this link
address and it will click at this link okay
okay that's the uh partial link test and the
that's the uh partial link test and the link text
link text now here the partial link text means
now here the partial link text means that we don't need to pass the complete
that we don't need to pass the complete value here you just need to pass a
value here you just need to pass a portion of the text like i said you need
portion of the text like i said you need to pass the portion of the next i have
to pass the portion of the next i have passed some address over here right so
passed some address over here right so through this also it will click at
through this also it will click at printed some address so let's uh
printed some address so let's uh practically do it first or uh just open
practically do it first or uh just open your
your intellij id id
intellij id id so i'll just create a different package
so i'll just create a different package over here
over here sorry i'll just create a different class
sorry i'll just create a different class over here
over here or link text and
or link text and partial link text so i'll just write
selenium tutorials
tutorials three
three okay
okay just click on dresses
okay so now by
by link
link text
text so it's going to be um
driver dot
dot fine element
fine element by
by dot
dot link text
link text okay
okay so now here i want um
so now here i want um i want to click on this link so how am i
i want to click on this link so how am i gonna do it i'm gonna
gonna do it i'm gonna inspect this element first
so i've inspected this element here you can see i have the printed
here you can see i have the printed chiffon dress which is written away this
chiffon dress which is written away this is the
is the link text i will copy this
and i will paste it over here and simply write
and simply write click
click okay
okay so now let's see
and here it is selected so here you can see this is printed
so here you can see this is printed chiffon dress
chiffon dress as i had written a printed chiffon dress
as i had written a printed chiffon dress dot click so here it's clicked
dot click so here it's clicked okay
okay now let's try it by partial link text
now let's try it by partial link text so i'll just simply
so i'll just simply command this
what i'm going to do is i'm going to write driver
write driver dot
dot find element
find element by dot
by dot partial link text and what i'm going to
partial link text and what i'm going to enter is chiffon dress
enter is chiffon dress and i'll click
this text okay so now let's run this
chrome browser's launch this maximize it is navigating
is navigating [Music]
and now it's clicked okay so now you can see
see through partial link text also my
through partial link text also my printed chiffon dress this this dress
printed chiffon dress this this dress this link is clicked
this link is clicked so now we have understood uh
id we have understood name then we have understood the partial link text and the
understood the partial link text and the link text
link text so next is class name
so next is class name now through class also we can locate our
now through class also we can locate our web element for example we have this
web element for example we have this text box name email address and we have
text box name email address and we have this uh syntax of html syntax now we
this uh syntax of html syntax now we have the attribute class over here here
have the attribute class over here here we have the class attribute form control
we have the class attribute form control the value is
the value is so how we're going to locate by class
so how we're going to locate by class simply just write driver dot find
simply just write driver dot find element by dot class
element by dot class form control send keys and whatever
form control send keys and whatever value you want to send away it's similar
value you want to send away it's similar to id and name there's no such
to id and name there's no such difference in it but this one thing is
difference in it but this one thing is that the class name that the value of
that the class name that the value of form control now this value can be of
form control now this value can be of multiple elements on a web page it's not
multiple elements on a web page it's not unique
unique whereas the id is a unique uh value
whereas the id is a unique uh value right which is given to each element for
right which is given to each element for each element the id value is different
each element the id value is different whereas for class the value for each
whereas for class the value for each element is similar
element is similar like for multiple elements there must be
like for multiple elements there must be a class name form control okay
a class name form control okay so in that case uh many of them don't
so in that case uh many of them don't use class the automation testers they
use class the automation testers they use class uh locator very less as
use class uh locator very less as compared to the id and the name
compared to the id and the name so the next locator that we have is the
so the next locator that we have is the tag name
tag name okay now tag name uh are used to find
okay now tag name uh are used to find multiple elements on the web page
multiple elements on the web page like let me tell you what is tag name
like let me tell you what is tag name like suppose um
like suppose um here you can see right this input this
here you can see right this input this is your tag name
is your tag name this is the tag name here over your
this is the tag name here over your input and the attributes are this type
input and the attributes are this type name id
name id these are the attributes that is used
these are the attributes that is used so tag name
so tag name are used to find multiple elements on
are used to find multiple elements on the web page
the web page for example suppose
suppose this page okay now i want to find the number of links
now i want to find the number of links present on this page
present on this page so how can i do that
so how can i do that i'll simply click on inspect
i'll simply click on inspect i'll find the anchor tags the number of
i'll find the anchor tags the number of anchor tags present on this page okay
anchor tags present on this page okay through that i can find out the number
through that i can find out the number of links that is present in this page
of links that is present in this page okay so tag name now your tag name like
okay so tag name now your tag name like a like here the a the anchor tag is used
a like here the a the anchor tag is used as a tag name now through this a that is
as a tag name now through this a that is the anchor tag we can locate the uh we
the anchor tag we can locate the uh we can find the number of links present on
can find the number of links present on this page
this page now remember tag name is used when we
now remember tag name is used when we want to find multiple things like
want to find multiple things like suppose i can now um
suppose i can now um [Music]
[Music] i if i want to find the number of
i if i want to find the number of sliders over here
sliders over here like how many sliders are present
like how many sliders are present so how am i going to do i'm going to
so how am i going to do i'm going to inspect the element like under every
inspect the element like under every anchor tag we have the image
anchor tag we have the image like suppose for example let me
like suppose for example let me inspect this
inspect this here
yeah you can see under every angle tag we have the image so the source image
we have the image so the source image resource so
resource so ah through this anchor tag i can inspect
ah through this anchor tag i can inspect the number of sliders that is there i
the number of sliders that is there i can inspect these sliders how many
can inspect these sliders how many sliders are present how many uh through
sliders are present how many uh through this image tag i can identify how many
this image tag i can identify how many images are present on this web pages so
images are present on this web pages so the tag is used to find multiple
the tag is used to find multiple elements on the web page
elements on the web page now for example it is mostly used like
now for example it is mostly used like if i want to find the number of sliders
if i want to find the number of sliders if i want to find the number of links on
if i want to find the number of links on this page if i want to find the number
this page if i want to find the number of images on this page so through this i
of images on this page so through this i can find the uh
can find the uh number of multiple items or multiple
number of multiple items or multiple elements on the web page
elements on the web page so let's implement that
so let's implement that so what i'm going to do is i'm going to
so what i'm going to do is i'm going to let's create a new
let's create a new class
class java class
java class write
write selenium
selenium tutorials
okay so i have created a new java class over here
over here i'll write driver.get
i'll write driver.get and this i'll write
and this i'll write inspect this element
okay we will inspect this we will try to find the number of links present on this
find the number of links present on this page okay
page okay let's see whether this
let's see whether this program runs properly or not
is maximized it is navigated to google.com okay
google.com okay so now um
so now um what i want to do is i want to find the
what i want to do is i want to find the number of links that is present on this
number of links that is present on this page okay there are many links like this
page okay there are many links like this image gmail
image gmail and there are links like hindi and the
and there are links like hindi and the different types of languages so i want
different types of languages so i want to i want to know the number of links
to i want to know the number of links that is present on this page so how am i
that is present on this page so how am i going to do that
going to do that okay
okay simply
simply i'll use the tag name tags over here
i'll use the tag name tags over here so here we will be using by tag name the
so here we will be using by tag name the locator so i'll just simply write driver
locator so i'll just simply write driver dot find elements i'll use find elements
dot find elements i'll use find elements over here because i have to find
over here because i have to find multiple elements over here okay
multiple elements over here okay by
by dot
dot tag name and here i'll write
tag name and here i'll write which tag do i need to inspect to find
which tag do i need to inspect to find the number of links that is present on
the number of links that is present on this page so i will be inspecting the
this page so i will be inspecting the anchor tags that is present
anchor tags that is present on this page right the number of anchor
on this page right the number of anchor tags i want to know the number of anchor
tags i want to know the number of anchor tags that is present on this page so
tags that is present on this page so i'll be using
i'll be using a this is the tag name which i want to
a this is the tag name which i want to inspect
inspect okay
now here i have used elements find elements right
elements right so what i'm going to do is i'm going to
so what i'm going to do is i'm going to um
um write a variable over here link is equal
write a variable over here link is equal to driver.find elements by dot name tag
to driver.find elements by dot name tag name
name now this link is of what type that we
now this link is of what type that we need to decide right
need to decide right so how are we gonna do that now here
this find elements okay this find elements need to return a list
this find elements need to return a list it needs to return a list of elements
it needs to return a list of elements it needs to return a list of web
it needs to return a list of web elements
elements where the elements are this a this
where the elements are this a this anchor tag the links that is present on
anchor tag the links that is present on the web page anything that is present on
the web page anything that is present on the web page is known as web elements
the web page is known as web elements right so we are uh returning a list of
right so we are uh returning a list of web elements right we need a list of web
web elements right we need a list of web elements so here we will be using the
elements so here we will be using the collections concept that is there in the
collections concept that is there in the java
java in which we have the list
that is a java util package and your
and your in list this a tag is what it is
in list this a tag is what it is identifying what it is identifying a web
identifying what it is identifying a web element right so i'll write a web
element right so i'll write a web element
element so this find element is designed to
so this find element is designed to return back a list of web element
return back a list of web element which is what is being assigned to the
which is what is being assigned to the variable
variable link
link okay
okay whose type is of what
whose type is of what list web element
list web element okay so now your uh there's a variable
okay so now your uh there's a variable link so what i'm gonna do is i'm gonna
link so what i'm gonna do is i'm gonna write
write s out
s out and
and link
link dot size now the size method is used to
dot size now the size method is used to find the number of uh elements that is
find the number of uh elements that is present okay number of elements that is
present okay number of elements that is present on the
present on the web page so this command through link
web page so this command through link dot size this method this method is used
dot size this method this method is used to find the number of elements okay
to find the number of elements okay so what i'm going to do is i'm going to
so what i'm going to do is i'm going to save it and
save it and let's run
chrome browser is launched it's maximized
it's maximized it's navigated
it's navigated and
and here you will see there are 20 total 27
here you will see there are 20 total 27 links present on the web page now what i
links present on the web page now what i want is i want the name of these links
want is i want the name of these links so how are we going to do that to print
so how are we going to do that to print those name i'll use the for loop
i'm simply going to write for and here
and here we are inspecting the web element
we are inspecting the web element so i'll write web element
so i'll write web element i'll name it as l and your i'll write
i'll name it as l and your i'll write link
s out and i will write l dot
l dot get
get text
text now the get text method is used to
now the get text method is used to retrieve the or to return the text that
retrieve the or to return the text that is uh
is uh inspecting that we are inspecting over
inspecting that we are inspecting over here we are inspecting the link right so
here we are inspecting the link right so it will get the text
it will get the text of those links that means i want the
of those links that means i want the name of the links that is uh that they
name of the links that is uh that they are identifying over here these 27 links
are identifying over here these 27 links right i want the name of these 27 links
right i want the name of these 27 links i'm adding for loop in which i have
i'm adding for loop in which i have given a web element l because i'm
given a web element l because i'm inspecting a web element that is the
inspecting a web element that is the links i'm inspecting i'm going to very
links i'm inspecting i'm going to very i've stored it in l
i've stored it in l and uh here i'm printing those
and uh here i'm printing those uh links the name of those links okay
uh links the name of those links okay so i'll just click
it's maximized it's navigated to google.com
and here you can see we have the different types of links that is present
different types of links that is present over here
over here okay
okay so through this way we can find the
so through this way we can find the number of uh
number of uh links and we can find the name of the
links and we can find the name of the links that is present that is we can
links that is present that is we can find
find we learnt the get text method and the
we learnt the get text method and the size method over here
size method over here okay
okay creating by css selector
creating by css selector now this css selector this is a type of
now this css selector this is a type of customized locator now before uh
customized locator now before uh studying the css selector we need to
studying the css selector we need to study some css concept
study some css concept so let's have a look at it
so let's have a look at it now for example we have a front
now for example we have a front page.html we have this html file we have
page.html we have this html file we have the html tags and everything and inside
the html tags and everything and inside the body tag we have this div tag okay
the body tag we have this div tag okay now we have written div class is equal
now we have written div class is equal to box i have given the class value as
to box i have given the class value as box okay and then i have given the
box okay and then i have given the uh
text and if like i have given a code inside this div element this div block
inside this div element this div block whatever it might be but the thing is
whatever it might be but the thing is over here is about the class and the id
over here is about the class and the id the difference between the class and the
the difference between the class and the id over here okay so we have this front
id over here okay so we have this front page dot html in which we have the div
page dot html in which we have the div tag inside the div tag we have the class
tag inside the div tag we have the class okay and the value of this class is box
okay and the value of this class is box so
so if i append the style sheet or in this
if i append the style sheet or in this html page so how will i style this class
html page so how will i style this class how will i style this div block
how will i style this div block so i'm going to style through this class
so i'm going to style through this class value that is box now how i'm going to
value that is box now how i'm going to do that to access this class i'm going
do that to access this class i'm going to write uh this
to write uh this dot do you see i'll be accessing it
dot do you see i'll be accessing it through a dot this is a period that is
through a dot this is a period that is used
used while accessing the class value okay
while accessing the class value okay so i'll write dot box and then whatever
so i'll write dot box and then whatever attributes i want to write like color
attributes i want to write like color green red or whatever it is whatever
green red or whatever it is whatever formatting i want to do or whatever
formatting i want to do or whatever style i need to add i'll add between
style i need to add i'll add between these blocks of code okay
these blocks of code okay so this is one concept for class we will
so this is one concept for class we will use a dot
use a dot now let's see for id now here we have
now let's see for id now here we have the front page dot html similar and we
the front page dot html similar and we have the div block in which we have the
have the div block in which we have the div id is equal to box one i have given
div id is equal to box one i have given the id value as box one so if i want to
the id value as box one so if i want to style it what i'm going to do i'm going
style it what i'm going to do i'm going to use the hash symbol over here here
to use the hash symbol over here here you can see i'm using the hash symbol to
you can see i'm using the hash symbol to access this id
access this id i'm going to use the hash symbol that is
i'm going to use the hash symbol that is the hash box one and then whatever our
the hash box one and then whatever our styling i want to perform i will perform
styling i want to perform i will perform between these blocks
between these blocks but the thing that i want you to
but the thing that i want you to understand over here is that for class
understand over here is that for class we are using the uh dot and for id we
we are using the uh dot and for id we are using the
are using the hash okay so this is the css concept we
hash okay so this is the css concept we you need to know what's the css selector
you need to know what's the css selector okay
okay so now uh locating by css selector that
so now uh locating by css selector that is the tag and id
is the tag and id now just assume we have this uh
now just assume we have this uh text box that is the email text box and
text box that is the email text box and this is this html syntax that we are
this is this html syntax that we are having
having now here for tag in id
now here for tag in id your tag what is your tag name your tag
your tag what is your tag name your tag name is this this is your tag name input
name is this this is your tag name input okay and these are your attributes like
okay and these are your attributes like the class id name these are your
the class id name these are your attributes right
attributes right so what you're going to do is like for
so what you're going to do is like for tag and id it is tag name hash id like
tag and id it is tag name hash id like as i said in the previous slide to
as i said in the previous slide to access id we use the hash right so over
access id we use the hash right so over here we'll use tag name hash id
here we'll use tag name hash id so how we're going to write is like
so how we're going to write is like driver dot find element
driver dot find element by dot css selector we'll use css select
by dot css selector we'll use css select over here
over here we'll write tag name first the tag name
we'll write tag name first the tag name is input so we'll write input
is input so we'll write input then we'll write hash
then we'll write hash hash
hash and then we are going to write the id
and then we are going to write the id value because it's tag and id the css
value because it's tag and id the css selector that we are using is tag and id
selector that we are using is tag and id right so we're going to write the id
right so we're going to write the id value that is email okay now this is
value that is email okay now this is case sensitive just write it the same
case sensitive just write it the same way which is it is written over here
way which is it is written over here so we're going to write input
so we're going to write input email dot send keys okay whatever uh
email dot send keys okay whatever uh text you want to send just send it over
text you want to send just send it over here
here so this is how you're going to write the
so this is how you're going to write the css director for tag and id
css director for tag and id now let's see for tag and class okay
now let's see for tag and class okay so here we have the text box email
so here we have the text box email address and we have the syntax over here
address and we have the syntax over here so how we gonna write for tag and class
so how we gonna write for tag and class for class we use the dot operator here
for class we use the dot operator here you can see we use a dot right
you can see we use a dot right so similarly before we were using hash
so similarly before we were using hash here you can see we were using hash for
here you can see we were using hash for id so for here we are using the dot for
id so for here we are using the dot for class
class it's the same thing we're just going to
it's the same thing we're just going to write driver dot find element by dot css
write driver dot find element by dot css selector
selector input dot
input dot that is a tag name your tag name is
that is a tag name your tag name is input
input dot
dot dot
dot class value the value of your class is
class value the value of your class is control right so i have written control
control right so i have written control over here dot send keys at the right abc
over here dot send keys at the right abc gmail.com whatever text you want to send
gmail.com whatever text you want to send over here
over here okay next we have the tag and attribute
okay next we have the tag and attribute okay so how we're going to work with tag
okay so how we're going to work with tag in attribute is tag name then we have
in attribute is tag name then we have the attribute name is equal to attribute
the attribute name is equal to attribute value now we can use any of the
value now we can use any of the attribute that we want
attribute that we want like over here we can use the
like over here we can use the driver.find element by.css selector
driver.find element by.css selector input
input name like here i can use id i can use
name like here i can use id i can use name i can use class anything i can use
name i can use class anything i can use so i'm using name name is equal to from
so i'm using name name is equal to from that is the attribute name is name my
that is the attribute name is name my attribute value is from here you can see
attribute value is from here you can see and my tag name is input
and my tag name is input okay
okay my next css locator is tag and class and
my next css locator is tag and class and attribute
attribute so how am i going to do that
so how am i going to do that simply i just have this text box that is
simply i just have this text box that is the email address and i have the syntax
the email address and i have the syntax over here
over here so what i'm going to do is uh over here
so what i'm going to do is uh over here for tag name
for tag name it's tag and class and attribute right
it's tag and class and attribute right so for tag name we'll first insert our
so for tag name we'll first insert our tag name that is the input
tag name that is the input then we have the uh class we want to uh
then we have the uh class we want to uh write the class for that we need to use
write the class for that we need to use the dot operator here we are using the
the dot operator here we are using the dot over here dot
dot over here dot the class value that we have is control
the class value that we have is control over here it's control then the
over here it's control then the attribute name now here i'm using id you
attribute name now here i'm using id you can use any of the attribute so i'm
can use any of the attribute so i'm using id is equal to email dot send keys
using id is equal to email dot send keys abc at the rate gmail.com
abc at the rate gmail.com okay so i hope it's clear for you
okay so i hope it's clear for you the css selector now see css selector is
the css selector now see css selector is not mostly used by the automation tester
not mostly used by the automation tester they don't use this css selector a lot
they don't use this css selector a lot instead of css selector they use the
instead of css selector they use the xpath
xpath see the frequently used locators are the
see the frequently used locators are the id
id the name
the name and for links we use the link text and
and for links we use the link text and the xpath the expert is used
the xpath the expert is used used frequently by all the automation
used frequently by all the automation testers because it is one of the most
testers because it is one of the most precise form to use the locator and it's
precise form to use the locator and it's it's tough to understand but uh once you
it's tough to understand but uh once you understand it it's very easy to use okay
understand it it's very easy to use okay because we have a crow path plug-in to
because we have a crow path plug-in to use that we will use that plug-in to uh
use that we will use that plug-in to uh find our x-path
okay next the one of the most important interview question that you will face is
interview question that you will face is that what is difference between the find
that what is difference between the find element and the find elements
element and the find elements okay
okay now uh we found this find element and
now uh we found this find element and find elements in tag name in tag name i
find elements in tag name in tag name i wrote a program in which i used find
wrote a program in which i used find elements because i wanted to find the
elements because i wanted to find the number of links on a web page right i
number of links on a web page right i wanted to find multiple web element on a
wanted to find multiple web element on a web page
web page so that's the
so that's the method used to find multiple element on
method used to find multiple element on a web page we use the find elements
a web page we use the find elements that's where i use file elements right
that's where i use file elements right so the first difference is that find
so the first difference is that find element
element this method is used to access a single
this method is used to access a single web element on a web page we will use to
web element on a web page we will use to access single element on the web page
access single element on the web page till now we were accessing find element
till now we were accessing find element because we wanted to access only one web
because we wanted to access only one web element that is the
element that is the text box or some other box that is the
text box or some other box that is the email box so we have to access only one
email box so we have to access only one web element so that is the reason why
web element so that is the reason why we're using find element
we're using find element whereas in find elements this method is
whereas in find elements this method is used to access multiple web element on a
used to access multiple web element on a web page in our case we were finding
web page in our case we were finding multiple angular tags the anchor tags
multiple angular tags the anchor tags that is the a tag that is used on our
that is the a tag that is used on our web page we were finding the number of
web page we were finding the number of links in our web page
links in our web page okay
okay next in find element when the element is
next in find element when the element is not found it throws an exception
not found it throws an exception see whenever the element is not found in
see whenever the element is not found in find element it will throw an exception
find element it will throw an exception such as no such element is found okay
such as no such element is found okay whereas in find elements when the
whereas in find elements when the element is not found it returns an empty
element is not found it returns an empty list it will return some empty list okay
list it will return some empty list okay next the final element it will find only
next the final element it will find only one web element whereas the find
one web element whereas the find elements will find the list of elements
elements will find the list of elements which matches the same locator like if
which matches the same locator like if we have uh written a as a tag name
we have uh written a as a tag name written over here
written over here in fine and we find the number of
in fine and we find the number of a tags so it will return the list of
a tags so it will return the list of elements that is the list of elements
elements that is the list of elements will be returned as i have shown in the
will be returned as i have shown in the program let me show you the program
program let me show you the program um
um here it is
here you can see it is returning the list of web elements that is it is
list of web elements that is it is returning the list of links
returning the list of links so the find elements
so the find elements the find elements will find the list of
the find elements will find the list of elements which matches the locator
elements which matches the locator now let me explain you when the element
now let me explain you when the element is not found
is not found like here you can see when the element
like here you can see when the element is not found it throws an exception no
is not found it throws an exception no such element found right so we're going
such element found right so we're going to do that i'll show that i'll implement
to do that i'll show that i'll implement that for you
that for you for example suppose um
okay and suppose
and suppose this by name okay
this by name okay i'm
i'm just writing search
just writing something so that you don't find the element i'm using the fine
find the element i'm using the fine element method over here
element method over here see what i'm trying to do is i am trying
see what i'm trying to do is i am trying to prove you this statement that when
to prove you this statement that when the element is not found it will throw
the element is not found it will throw an exception no such element found i'm
an exception no such element found i'm trying to prove this statement
trying to prove this statement just check it out
okay so i have changed the value over here now let's see
so let's see see here you can see no such element
see here you can see no such element exception no such element unable to
exception no such element unable to locate element here you can see
locate element here you can see we have got an error over here here you
we have got an error over here here you can see name is equal to search
can see name is equal to search underscore q u
underscore q u unable to locate element that's what i
unable to locate element that's what i try i said right
try i said right for a fine element when you're using
for a fine element when you're using find element and the element is not
find element and the element is not found you will get an exception that no
found you will get an exception that no such element found or unable to locate
such element found or unable to locate the element whereas in fine elements we
the element whereas in fine elements we will return an empty list now let's try
will return an empty list now let's try to do
to do this one
we use the find elements method here right find elements now let me change
right find elements now let me change the tag to
the tag to suppose i'm changing to ar okay
suppose i'm changing to ar okay this is what the tag i'm changing and
this is what the tag i'm changing and i'll just comment
i'll just comment this for
this for time being
let's navigate it here you can see are we getting any
here you can see are we getting any list of array it's just simply zero
list of array it's just simply zero number of uh
we didn't find any tag name a r over here so it just returned zero so that's
here so it just returned zero so that's what it said that it won't give any uh
what it said that it won't give any uh error or something it will just return
error or something it will just return an empty list it will just return like
an empty list it will just return like if the element is not for it will return
if the element is not for it will return an empty list over here it returns zero
an empty list over here it returns zero so there is no uh tag name name f a r
so there is no uh tag name name f a r so this is what is the difference
so this is what is the difference between find element and fine elements
between find element and fine elements this is one of the interview question
this is one of the interview question which is asked in selenium and it is one
which is asked in selenium and it is one also one of the most important question
also one of the most important question that is asked
that is asked so this is all for today in the next
so this is all for today in the next tutorial we will learn what is xpath and
tutorial we will learn what is xpath and we will execute we will practically
we will execute we will practically implement that we will also download the
implement that we will also download the crow path
crow path plugin that we used for uh
plugin that we used for uh xpath
xpath hello everyone my name is varsha and
hello everyone my name is varsha and welcome to programming knowledge
welcome to programming knowledge so in today's tutorial we are going to
so in today's tutorial we are going to create test cases and we're going to
create test cases and we're going to execute them
execute them but before that let us understand what
but before that let us understand what we did in the previous tutorial so in
we did in the previous tutorial so in the previous tutorial we learned what
the previous tutorial we learned what are the web elements what are the
are the web elements what are the different types of web elements and one
different types of web elements and one of the most important concept that we
of the most important concept that we learnt in the previous tutorial was the
learnt in the previous tutorial was the locators now the locators are the way to
locators now the locators are the way to identify a web element on a web page and
identify a web element on a web page and we discuss the different types of
we discuss the different types of locators like the id name
locators like the id name tag name class name the link text and
tag name class name the link text and the partial link text and also we
the partial link text and also we discussed about the css selector in the
discussed about the css selector in the previous tutorial
previous tutorial so uh the id name and the class name are
so uh the id name and the class name are the attributes that is used in the html
the attributes that is used in the html through which we can identify the web
through which we can identify the web element
element whereas the link text and the tag name
whereas the link text and the tag name these two are used uh first of all the
these two are used uh first of all the link text is basically used to click a
link text is basically used to click a link on a particular web page if you
link on a particular web page if you want to click on some link we use the
want to click on some link we use the link text whereas the tag name is used
link text whereas the tag name is used to retrieve multiple elements on a
to retrieve multiple elements on a webpage like for example i want to know
webpage like for example i want to know the number of links present on the
the number of links present on the particular page so i'm going to inspect
particular page so i'm going to inspect the tag name that is the anchor tag that
the tag name that is the anchor tag that is the a tag and i'm going to count how
is the a tag and i'm going to count how many a tags are present on that web page
many a tags are present on that web page to which i will uh retrieve multiple
to which i will uh retrieve multiple elements so that is uh that
elements so that is uh that for the so for that we are using tag
for the so for that we are using tag name whereas the css selector we use the
name whereas the css selector we use the tag in id we have the tag in class we
tag in id we have the tag in class we have tag and attribute we have tag class
have tag and attribute we have tag class and attribute so these are the different
and attribute so these are the different types of css selector also we understood
types of css selector also we understood in the previous tutorial so these were
in the previous tutorial so these were the some of the concepts that we learnt
the some of the concepts that we learnt in the previous tutorial now in this
in the previous tutorial now in this tutorial we are going to create test
tutorial we are going to create test cases and we are going to execute it
cases and we are going to execute it what i'm going to do is i'm going to
what i'm going to do is i'm going to create a test case in which we're going
create a test case in which we're going to open the chrome browser
to open the chrome browser i'm going to navigate to this url
i'm going to navigate to this url this page that you're seeing right i'm
this page that you're seeing right i'm going to navigate to this url i'm going
going to navigate to this url i'm going to enter the valid username and password
to enter the valid username and password and click on login button
and click on login button next i'm going to verify the title of
next i'm going to verify the title of the page that is the orange hrm and i'm
the page that is the orange hrm and i'm also going to verify the url that is
also going to verify the url that is specified over here
specified over here see the main intention behind this
see the main intention behind this tutorial
tutorial is that we're going to learn different
is that we're going to learn different types of commands in this also we are
types of commands in this also we are going to learn how to verify an element
going to learn how to verify an element like in manual testing we use the
like in manual testing we use the expected result and the actual result
expected result and the actual result and the status column is present right
and the status column is present right in which you have to match the results
in which you have to match the results and pass the status that it is fail or
and pass the status that it is fail or passed
passed so over here also we are going to verify
so over here also we are going to verify some elements like i am going to verify
some elements like i am going to verify the title of the page we are going to
the title of the page we are going to verify the
verify the url of the page so these are some of the
url of the page so these are some of the elements that we are going to verify
elements that we are going to verify today before that let us understand some
today before that let us understand some of the commands that we use in the
of the commands that we use in the previous tutorial let's understand that
previous tutorial let's understand that let's revise that the first command that
let's revise that the first command that we used was the form command that is the
we used was the form command that is the send keys command
send keys command here you can see the send keys command
here you can see the send keys command which is used to send a particular
which is used to send a particular text to the particular element right
text to the particular element right then we use the click command which is
then we use the click command which is used to click an element
used to click an element then we use the get command which is
then we use the get command which is used to navigate to the url
used to navigate to the url next we use the get text command which
next we use the get text command which is used to retry specific elements text
is used to retry specific elements text if you remember that
if you remember that we were using uh
we were using uh we were counting the number of links in
we were counting the number of links in a page right so in that i wanted to know
a page right so in that i wanted to know the name of those links so we use the
the name of those links so we use the get text command
get text command next we learnt about the size command
next we learnt about the size command the size command is used to get the
the size command is used to get the number of elements in the list
number of elements in the list now uh if you remember
now uh if you remember while
while while counting the number of links we we
while counting the number of links we we use the size command to know how many
use the size command to know how many links are present on the web page
links are present on the web page next we use the
next we use the driver.manage.window.maximize command
driver.manage.window.maximize command which is used to maximize the window
which is used to maximize the window next we use the system dot set property
next we use the system dot set property as you know it is the very first line
as you know it is the very first line on in our
on in our program so which is used to set a value
program so which is used to set a value and a key the key is like the
and a key the key is like the webdriver.chrome.driver and the value is
webdriver.chrome.driver and the value is the path of your executable file
the path of your executable file okay so these were the commands that we
okay so these were the commands that we learned in the previous tutorial so now
learned in the previous tutorial so now here i have prepared some of the test
here i have prepared some of the test cases first is open the chrome browser
cases first is open the chrome browser we will navigate to the url enter the
we will navigate to the url enter the valid username enter the valid password
valid username enter the valid password next we will click on login button then
next we will click on login button then we are going to verify the url and then
we are going to verify the url and then we are going to verify the title and
we are going to verify the title and then we will close the browser
then we will close the browser so these are the some of the steps that
so these are the some of the steps that we are going to perform today so let's
we are going to perform today so let's get started
get started now open your intelligent idea id
now open your intelligent idea id i'm going to create a new
i'm going to create a new class over here
class over here in my project
in my project okay so now i have created a new class i
okay so now i have created a new class i have named it as selenium tutorials file
have named it as selenium tutorials file and i have opened my chrome browser
and i have opened my chrome browser these are the two commands that i've
these are the two commands that i've used that is the system.set property
used that is the system.set property next i have used the web driver driver
next i have used the web driver driver is equal to new chrome driver
is equal to new chrome driver next i have navigated to the url this is
next i have navigated to the url this is the url and i have maximized the window
the url and i have maximized the window these are the commands that we have been
these are the commands that we have been learning in the previous tutorial also
learning in the previous tutorial also so now what i want is i want to uh enter
so now what i want is i want to uh enter valid username and valid password over
valid username and valid password over here so i'm going to simply click on
here so i'm going to simply click on this element and click on inspect
this element and click on inspect here you can see there are different
here you can see there are different attributes used so i'll use the id
attributes used so i'll use the id attribute first
so i'm gonna write driver dot
dot find element
find element by dot id
by dot id i'm going to enter the value that is
i'm going to enter the value that is there this is case sensitive so enter
there this is case sensitive so enter the same value
the same value and what i want to do is i want to send
and what i want to do is i want to send some value to it right
some value to it right so i'm going to write send keys and i'm
so i'm going to write send keys and i'm going to enter the valid username here
going to enter the valid username here you can see the username and the
you can see the username and the password is given this is a demo website
password is given this is a demo website which is normally used for automation so
which is normally used for automation so you can also use this and you can
you can also use this and you can automate this
automate this website so the username here uses admin
website so the username here uses admin so i'm going to copy this
so i'm going to copy this i'm going to paste it away
so here i've entered a valid username now i'm going to enter the valid
now i'm going to enter the valid password
so for that i'm going to write driver again
i'm going to write by dot i'll use name
here you can see this name attribute i'm going to copy this
going to copy this paste it over here
paste it over here i'm going to send some information to it
the password is given over yours so i'll just simply copy this password
and i'll paste it over here so here we have entered the valid
so here we have entered the valid username and valid password
username and valid password so i have entered the valid username and
so i have entered the valid username and password next i have to click on login
password next i have to click on login button
button so
so i'm going to inspect this login button i'll simply click on inspect
button i'll simply click on inspect and here you can see we have the name
and here you can see we have the name class id
class id so i'll use the id
i'll use driver dot find element
by dot id now enter the value and what i want
id now enter the value and what i want to do is i want to click this right so
to do is i want to click this right so i'll write right click
i'll write right click okay so now let's run this
my chrome browser browser is launched successfully
successfully it's navigated
okay there is some problem to it
[Music] okay here you can see i have given some
okay here you can see i have given some space so there is no space and password
it's launched it's navigated and my admin and password okay it's
admin and password okay it's login successfully
okay so now what i want is that i want to verify the title of the page and i
to verify the title of the page and i want to verify the
want to verify the url that is present over here
url that is present over here okay so let's verify that
so first we will verify the url let's verify the url
verify the url now for that we're going to use the get
now for that we're going to use the get current url
current url this is the command that we're going to
this is the command that we're going to use to verify the url now this command
use to verify the url now this command returns the current url of the web page
returns the current url of the web page okay
okay so let's see
so let's see what we're going to do is we're going to
what we're going to do is we're going to write
write driver dot
driver dot get
get current url
current url okay
okay and we're going to store this in a
and we're going to store this in a variable we're going to store this in a
variable we're going to store this in a string type variable
let me write the actual url
okay so we are storing in a string type variable i have named it a variable as
variable i have named it a variable as actual url and i have written string
actual url and i have written string actual url is equal to driver dot get
actual url is equal to driver dot get current url okay
current url okay now let me print this
let's see the actual url of this webpage and then we will verify it first
and then we will verify it first so let's run
my chrome browser is launched it's
it's navigated
navigated and the username and password has
and the username and password has entered its login successfully
and here it is this is my current url that i'm getting
this is my current url that i'm getting okay
okay now i am on this page i'm on the
now i am on this page i'm on the dashboard page so that is the reason why
dashboard page so that is the reason why i'm getting this url
i'm getting this url the current url retrieves the url of the
the current url retrieves the url of the current page okay your your on which
current page okay your your on which page on that page the url will be
page on that page the url will be retrieved
retrieved so here we have printed the url now
so here we have printed the url now let's verify it
let's verify it so now i have to verify it right how how
so now i have to verify it right how how am i going to do that
am i going to do that now
now i have already created a string variable
i have already created a string variable that is the actual url in which i have
that is the actual url in which i have got the current url of the web page
got the current url of the web page now what i am going to do is i am going
now what i am going to do is i am going to create another variable of the string
to create another variable of the string type in which i will store the desired
type in which i will store the desired url
url and i'm going to match both these url
and i'm going to match both these url okay so this is what we're going to do
okay so this is what we're going to do it so first we will create a string type
it so first we will create a string type variable and i'm write it i'm going to
variable and i'm write it i'm going to write it as
write it as desired
desired let's go url
let's go url and i will
and i will paste this url that i am getting
okay next
next i'm going to match this actual url and
i'm going to match this actual url and desired url
desired url for that i'll be using the if command
simply i'll write the actual url dot equals
now if they are equal what i'm going to print is i'm going to print
pass and if they're not
and if they're not then i'm going to print
okay so let's see
so let's see let's run this command
it's navigated okay i've entered the valid
navigated okay i've entered the valid username and password and it's
username and password and it's successfully logging
successfully logging and here it is
and here it is i have got the
i have got the actual url is also retrieved by the
actual url is also retrieved by the current get current url command and also
current get current url command and also the actual url and the desired url
the actual url and the desired url both are matching so the uh output is
both are matching so the uh output is passed now what if i change this url if
passed now what if i change this url if i write
i write rn.com so now let's run this command
rn.com so now let's run this command now you see the output will be fail
browser is maximized valid username and password is entered and
password is entered and here it is on the dashboard page
here it is on the dashboard page now let's see see
now let's see see here you can see the output it's failing
here you can see the output it's failing why it's fail because i have changed the
why it's fail because i have changed the desired url the desired url that i want
desired url the desired url that i want is the open source demo orange
is the open source demo orange hrmlife.com and the actual url that i'm
hrmlife.com and the actual url that i'm getting is this
getting is this okay so that is the reason why it's fair
okay so that is the reason why it's fair so this is how you can verify the url of
so this is how you can verify the url of a web page
a web page next let's
next let's verify the title of the page
verify the title of the page okay
okay similarly if you're going to verify the
similarly if you're going to verify the title of the page the same way for that
title of the page the same way for that the command that we will use is the
the command that we will use is the get title command
okay so what you're going to do is we're
so what you're going to do is we're going to simply write string
actual title that will be driver dot
that will be driver dot get title
get title okay
okay next
next let's print this title
i'm going to write actual title [Music]
[Music] and let's see
my chrome browser is launched it's navigated
valid username password is entered it's login
so this is the title that i got the first one is the i got the current url
first one is the i got the current url then the test case that i have verified
then the test case that i have verified is par is failed because i have written
is par is failed because i have written the desired url that i want is this and
the desired url that i want is this and the actual url that i'm getting is this
the actual url that i'm getting is this the next one is that i'm printing the
the next one is that i'm printing the title of the page that is the orange hrm
title of the page that is the orange hrm now how do we get the title simply just
now how do we get the title simply just inspect this page
and here in the head tag you can see the title here you can see it's orange hrm
title here you can see it's orange hrm so this is the title of the page okay so
so this is the title of the page okay so this is this is the desired title that
this is this is the desired title that you want
you want okay
okay so what you're going to do is
so what you're going to do is similarly we're going to write string
desired title
title that we want is the
that we want is the orange hrm this title that we want is
orange hrm this title that we want is we're going to match this
we're going to match this we're going to simply place it over here
now we will verify it you will verify with the if command i'm
you will verify with the if command i'm going to write if
going to write if the actual title dot equals
the actual title dot equals and we're going to write the desired
and we're going to write the desired title
and here we're going to write if my
write if my if my test case is passed
if my test case is passed then i'll write
then i'll write pass
pass and if it's not if it's not matching
and if it's not if it's not matching then
then i'm going to write
okay so now let's run
okay now i've launched its login and we have login successfully
and we have login successfully let's see
let's see now here we can see the current url my
now here we can see the current url my test case is passed
test case is passed next i can see the title of the page
next i can see the title of the page that is the orange hrm and the desired
that is the orange hrm and the desired title and the title that i'm getting
title and the title that i'm getting the actual title they both are matching
the actual title they both are matching so the test case is passed what if what
so the test case is passed what if what if i change this desired title
if i change this desired title and now let's see
okay my chrome browser is launched it's navigated
and here you can see it's failing okay
okay so we have verified our title we have
so we have verified our title we have verified our url the next command that
verified our url the next command that we're going to use is
we're going to use is the
the driver dot
driver dot close
so this command is used to close the browser
so let's run this again
run this again [Music]
we have opened a chrome browser it's launched
launched it's navigated
it's navigated it's maximized and
log in successfully and here it says it's pass our
it's pass our the current url is retrieved the test
the current url is retrieved the test cases of verifying the url is pass
cases of verifying the url is pass next the
next the actual title of the web page is
actual title of the web page is retrieved and the test cases fail
retrieved and the test cases fail because i have
because i have written only orange hr so let's change
written only orange hr so let's change it and save it and let's run it again
my chrome browser is launched it's navigated
it's maximized the valid pass username password is entered and here it is okay
password is entered and here it is okay and it's closed also
so this is the current url the test case of verifying the url is
the test case of verifying the url is passed this is the current title
passed this is the current title and the test case for verifying the
and the test case for verifying the title is passed
title is passed so this is how you can verify the url
so this is how you can verify the url and the title
and the title these are the different commands and the
these are the different commands and the different commands that we learned today
different commands that we learned today is one is the get current url then we
is one is the get current url then we learnt the get title
learnt the get title also and we learned how to verify the
also and we learned how to verify the commands okay so this is what we learned
commands okay so this is what we learned today we executed this test case we
today we executed this test case we opened the chrome browser we navigated
opened the chrome browser we navigated to the url we entered the valid username
to the url we entered the valid username the valid password we clicked on login
the valid password we clicked on login we
we verified the url we verified the title
verified the url we verified the title of the web page next we close the
of the web page next we close the browser so we executed these test cases
browser so we executed these test cases by executing these test cases we learned
by executing these test cases we learned how to verify the title we learned how
how to verify the title we learned how to verify the
to verify the url also we learned different commands
url also we learned different commands we learnt like the get title command and
we learnt like the get title command and the get current
the get current url command okay so there is also one
url command okay so there is also one more command that i want to explain you
more command that i want to explain you is the get paid source command which is
is the get paid source command which is usually used to get the page source that
usually used to get the page source that is the source code of the page that we
is the source code of the page that we are on
are on so these are some of the get commands
so these are some of the get commands that i'm explaining you these are
that i'm explaining you these are frequently used by the automation
frequently used by the automation testers
testers so uh we're going to write the driver
so uh we're going to write the driver dot
dot get page source
get page source and we're going to store this in an
and we're going to store this in an element
element sorry we're going to store this in a
sorry we're going to store this in a string type variable
i'm going to write the page source that is ps
is ps and we're going to simply print it
so my chrome browser is launched this navigated and
navigated and okay so here you can see that my source
okay so here you can see that my source code that is the page source code is
code that is the page source code is visible over here
visible over here this is the source code that i have got
this is the source code that i have got okay
okay so this is also one of the command which
so this is also one of the command which is used that is the get page source
is used that is the get page source this is used to get the source code of
this is used to get the source code of the page that we are navigated to
the page that we are navigated to so in this tutorial we learned the three
so in this tutorial we learned the three commands that is the get paid source we
commands that is the get paid source we learned the get title and we learned to
learned the get title and we learned to get current url
get current url okay
okay so in the get source we learned that we
so in the get source we learned that we uh through get page source we can get
uh through get page source we can get the page source we can get the source
the page source we can get the source code of the page next we learn through
code of the page next we learn through get title command we learned how to get
get title command we learned how to get the title of the web page next we
the title of the web page next we learned the get current url which is
learned the get current url which is used to get the current url of the page
used to get the current url of the page so these were the three uh get commands
so these were the three uh get commands that we learned in the today's tutorial
that we learned in the today's tutorial so in the next tutorial we are going to
so in the next tutorial we are going to learn about uh the xpath we are going to
learn about uh the xpath we are going to use the group plugin the crowpart plugin
use the group plugin the crowpart plugin for the chrome browser
for the chrome browser and through that chrome brow crop path
and through that chrome brow crop path plugin we are going to uh retrieve our x
plugin we are going to uh retrieve our x part
part so we're going to study what are the
so we're going to study what are the different types of xpath also
different types of xpath also so in this tutorial you will understand
so in this tutorial you will understand about the xpath
about the xpath you will understand what is xpath how to
you will understand what is xpath how to locate the element using the xpath
locate the element using the xpath we will also understand about the crow
we will also understand about the crow path plugin the types of xpath what are
path plugin the types of xpath what are their syntax
their syntax then we will understand the difference
then we will understand the difference between the absolute and the relative x
between the absolute and the relative x path and out of the absolute and
path and out of the absolute and relative x path which one is preferred
relative x path which one is preferred and why
and why so let's get started
first let us understand what is x path now as i said it is a part of a locator
now as i said it is a part of a locator here you can see this chart right we
here you can see this chart right we have the different types of locators as
have the different types of locators as i discussed in the previous tutorial i
i discussed in the previous tutorial i discussed about the id name link text
discussed about the id name link text the partial linked text the tag name the
the partial linked text the tag name the class name and then the css selector
class name and then the css selector we are left with xpath now there are
we are left with xpath now there are different types of xpath like the
different types of xpath like the relative expert and the absolute xpath
relative expert and the absolute xpath and it comes under the customized
and it comes under the customized locators
locators as i discussed in the previous tutorial
as i discussed in the previous tutorial locators are the way to find an html
locators are the way to find an html element on a web page
element on a web page expert is used when we don't have the id
expert is used when we don't have the id the name the tag name locators present
the name the tag name locators present in the html that is when we use xpath
in the html that is when we use xpath like here you can see in selenium
like here you can see in selenium automation if the elements are not found
automation if the elements are not found by the general locators like the id
by the general locators like the id class name
class name or the link text the partial link text
or the link text the partial link text the tag name etc
the tag name etc then the xpath is used to find an
then the xpath is used to find an element on the web page
element on the web page xpath is also defined as the xml path
xpath is also defined as the xml path the shortcut the short name of xpath is
the shortcut the short name of xpath is the xml path
the xml path now xpath is basically a syntax or a
now xpath is basically a syntax or a language for finding any element on the
language for finding any element on the web page using the xml path expression
web page using the xml path expression as i said xml path is defined as the xml
as i said xml path is defined as the xml path right
path right to find any element we use the xml path
to find any element we use the xml path expression now this x path
expression now this x path is the address of element using the html
is the address of element using the html dom structure by using the html dom
dom structure by using the html dom structure we will find the xml path
structure we will find the xml path expression now what is this html dome
expression now what is this html dome structure
structure now here you can see we have the normal
now here you can see we have the normal html code that we write usually we have
html code that we write usually we have the html head title body and we close
the html head title body and we close the html tag this is the normal html
the html tag this is the normal html code that we usually write
code that we usually write but when a web page is loaded the
but when a web page is loaded the browser automatically creates a dom
browser automatically creates a dom structure that is the document object
structure that is the document object model
model here you can see this is the dom model
here you can see this is the dom model like we have the document we have the
like we have the document we have the html tag oh that is the root element
html tag oh that is the root element then we have the head we have the title
then we have the head we have the title we have the body under body we have the
we have the body under body we have the different types of elements so this is
different types of elements so this is the dom model that is the dom structure
the dom model that is the dom structure why it is called as a dom structure
why it is called as a dom structure because
because the browser automatically creates a dom
the browser automatically creates a dom structure that is the nodes that is a
structure that is the nodes that is a different nodes are created
different nodes are created automatically over here you can see we
automatically over here you can see we have the html head title is just simply
have the html head title is just simply written over here but over here we have
written over here but over here we have the nodes there are nodes present over
the nodes there are nodes present over here so that is the reason why it is
here so that is the reason why it is called the html dom structure and it is
called the html dom structure and it is created automatically by the browser
created automatically by the browser dom is basically an api interface that
dom is basically an api interface that is provided by the browser
is provided by the browser now see if we go detailing into the dom
now see if we go detailing into the dom structure it's a very huge concept but
structure it's a very huge concept but for now to understand that the x path
for now to understand that the x path the xml expression that we will derive
the xml expression that we will derive we will derive from the html dom
we will derive from the html dom structure you know this structure that
structure you know this structure that we have we will derive from this
we have we will derive from this for example
for example so this is the web page now if i want to
so this is the web page now if i want to uh inspect any of the element i'll
uh inspect any of the element i'll quickly i simply click on inspect and
quickly i simply click on inspect and here you see
here you see this is the dom structure of a web page
this is the dom structure of a web page like we have the html head body the html
like we have the html head body the html tag is closed inside head we have
tag is closed inside head we have different types of meta property we have
different types of meta property we have the style we have the script so all
the style we have the script so all these are the
these are the so all these are in the form of the
so all these are in the form of the html dom structure
html dom structure okay
so when a web page is loaded the browser automatically creates this dom object
automatically creates this dom object and
and this dom is an api interface that is
this dom is an api interface that is provided by the browser
provided by the browser okay
okay next let us see how can we capture the x
next let us see how can we capture the x path
now this is the page that we want to inspect now suppose this is the email
inspect now suppose this is the email address uh
address uh field we have and we want to inspect
field we have and we want to inspect this element
this element so i'll simply click on inspect and here
so i'll simply click on inspect and here you can see this text box is highlighted
you can see this text box is highlighted right
right now i'm i want to capture the x path of
now i'm i want to capture the x path of this text box how am i going to do that
this text box how am i going to do that i will uh
i will uh simply
simply this syntax i will simply right click
this syntax i will simply right click over here
over here go to copy and i will click on copy full
go to copy and i will click on copy full xpath see here i have two options i have
xpath see here i have two options i have copy xpath and i have copy full xpath so
copy xpath and i have copy full xpath so i will use copy full expert there is a
i will use copy full expert there is a difference between the two you will
difference between the two you will understand that later
understand that later but for now let's
but for now let's click on copy full expat
click on copy full expat paste it over here
paste it over here okay
okay so here you see
so here you see this is the complete xpath that we are
this is the complete xpath that we are having
having for this field that is the email address
for this field that is the email address how is it
how is it first we have the html then we have the
first we have the html then we have the body then we have the different div tags
body then we have the different div tags that we have over here and the last we
that we have over here and the last we have the input because we want to access
have the input because we want to access this element we have the input tag over
this element we have the input tag over here
here now here you can see these numbers one
now here you can see these numbers one two one
two one these are the index numbers that is
these are the index numbers that is present over here
present over here okay these are the index number that is
okay these are the index number that is given away that is the first element of
given away that is the first element of div under the first element of div i am
div under the first element of div i am selecting the second div under the
selecting the second div under the second div i'm selecting the first dev
second div i'm selecting the first dev as you can see there are different divs
as you can see there are different divs over here
over here so uh through these uh acts by accessing
so uh through these uh acts by accessing these divs i have reached to input tag
these divs i have reached to input tag and over here i'm accessing the email
and over here i'm accessing the email address that is this field
address that is this field okay so this is how we can access uh
okay so this is how we can access uh so this is the first method of accessing
so this is the first method of accessing the xpath the second method that we have
the xpath the second method that we have is the pro path plugin
okay so what we'll do is uh we'll simply go to google and type
go to google and type crow path plugin
crow path plugin the very first link that we have i'll
the very first link that we have i'll give the link in the description box
give the link in the description box just simply click add to chrome
and it is added okay
okay now here you can see
now here you can see there is no option away of crow path but
there is no option away of crow path but now uh let me refresh this page i'll
now uh let me refresh this page i'll just close this browser
and here you can see we have the option crow path
crow path because we have added the extension to
because we have added the extension to the chrome browser so we can see this
the chrome browser so we can see this option crow path
option crow path okay now i inspected this element
okay now i inspected this element this element i have inspected so let's
this element i have inspected so let's see the crow path
see the crow path and here it is
and here it is so here you can see this crow path right
so here you can see this crow path right uh we have the relative x path now as i
uh we have the relative x path now as i said the x path are of two types that is
said the x path are of two types that is the relative x path and the absolute x
the relative x path and the absolute x path
path then the css selector we have the hash
then the css selector we have the hash id the hash is used for uh
id the hash is used for uh id write
id write sorry the css directory that we have is
sorry the css directory that we have is the hash email now hash is used when we
the hash email now hash is used when we are accessing the id over here the id
are accessing the id over here the id that we have is email or if you can see
that we have is email or if you can see it's emailed
here it is it's email okay next the absolute expire this is the
next the absolute expire this is the absolute x bar that we are having
absolute x bar that we are having and the tag name that we are using that
and the tag name that we are using that is the input
is the input here you can see
here you can see the crow path is basically used to find
the crow path is basically used to find the x path of any element
the x path of any element and it is mostly used because it is used
and it is mostly used because it is used to find the element move more precisely
to find the element move more precisely like suppose if i will copy this
like suppose if i will copy this and here you can see the difference
and here you can see the difference this x path is different from this x
this x path is different from this x path why because we are indicating index
path why because we are indicating index number for each and every div that we
number for each and every div that we have here you can see there is no index
have here you can see there is no index number for this three divs but over here
number for this three divs but over here we have the index number given over here
we have the index number given over here why
why because uh
because uh crow path plugin is used to find the
crow path plugin is used to find the element more accurately okay
element more accurately okay that is the reason why we use crow path
that is the reason why we use crow path plugin there were previous plugins also
plugin there were previous plugins also that were used that is the firebug
that were used that is the firebug plugin the firepath plugin but they are
plugin the firepath plugin but they are outdated mostly crow path plugin is used
outdated mostly crow path plugin is used by the companies
by the companies and
and and the second most reason is that here
and the second most reason is that here you can see we have the relative x bar
you can see we have the relative x bar the css selector that it is selecting
the css selector that it is selecting the tag name that it is using so all
the tag name that it is using so all these things are present over here it is
these things are present over here it is showing these things so whereas over
showing these things so whereas over here if we you can just simply copy
here if we you can just simply copy full xpath and that's the option over
full xpath and that's the option over here so that is the reason why we use
here so that is the reason why we use the crow path plugin
the crow path plugin okay
okay now this is one thing
now this is one thing so the next thing that i want to explain
so the next thing that i want to explain is that suppose you have any of a
is that suppose you have any of a expert suppose this is the expert that
expert suppose this is the expert that you have and you want to find the x bar
you have and you want to find the x bar this x part is of which element so what
this x part is of which element so what you're going to do is i'll simply copy
you're going to do is i'll simply copy this
this i will click on this source code control
i will click on this source code control f here you can see find by string
f here you can see find by string selector or xpath
selector or xpath i will place my xpath over here and here
i will place my xpath over here and here you can see
you can see here it is
here it is i'm placing my password field over here
i'm placing my password field over here this x path indicates the password field
this x path indicates the password field that i have so this is how also you can
that i have so this is how also you can find the element through the x path
find the element through the x path and by using crow path you are finding
and by using crow path you are finding the x path that is the absolute x bar
the x path that is the absolute x bar and the relative x path as well okay
and the relative x path as well okay okay so
okay so now you have got an idea of how to
now you have got an idea of how to capture the x-path this is a small
capture the x-path this is a small example of it which is very easier form
example of it which is very easier form now suppose this is the html syntax that
now suppose this is the html syntax that i have for the username password and
i have for the username password and login button now if i want to access my
login button now if i want to access my login button through xpath
login button through xpath if i want to click on this login button
if i want to click on this login button through my x bar
through my x bar so how am i going to uh capture the x
so how am i going to uh capture the x path of this login button
path of this login button the very first thing that we have is the
the very first thing that we have is the forward slash
forward slash this forward slash is very important it
this forward slash is very important it is used to access the element okay
is used to access the element okay forward slash and then first i'm
forward slash and then first i'm accessing the html
accessing the html again a forward slash then i'm accessing
again a forward slash then i'm accessing the body tag
the body tag again a forward slash then i'm accessing
again a forward slash then i'm accessing the form tag
the form tag again a forward slash and then i'm
again a forward slash and then i'm accessing the input type that is the
accessing the input type that is the index three that is one two three the
index three that is one two three the third input uh tag
third input uh tag that i want to access because i want to
that i want to access because i want to click on the login button right here you
click on the login button right here you can see the syntax it's input type
can see the syntax it's input type submit name submit and the value is
submit name submit and the value is login this is the login button that we
login this is the login button that we are having for this and i want to access
are having for this and i want to access this login button i want to click on
this login button i want to click on this login button for that the x bar
this login button for that the x bar that we're going to use is this one
that we're going to use is this one over here the three indicates the index
over here the three indicates the index number that is the third input
number that is the third input type
type that is the third input tag name i want
that is the third input tag name i want to access so this is how you will write
to access so this is how you will write your x path
your x path so next now let us understand the
so next now let us understand the different types of x path that is the
different types of x path that is the relative x path and the absolute expo
relative x path and the absolute expo there are two types of x bar relative
there are two types of x bar relative and absolute x bar
and absolute x bar let's see the absolute x
let's see the absolute x now the absolute x path it contains the
now the absolute x path it contains the complete path from the root element to
complete path from the root element to the desired element
the desired element okay
okay for example
for example here you can see my root element is html
here you can see my root element is html and my desired element is this that is
and my desired element is this that is the input type submit name submit value
the input type submit name submit value login this is my desired
login this is my desired okay so i want to i have to uh for
okay so i want to i have to uh for absolute xpath i have to access from
absolute xpath i have to access from root element to the desired element
root element to the desired element that's what i'm doing over here i'm
that's what i'm doing over here i'm writing a forward slash that is only one
writing a forward slash that is only one forward slash
forward slash then i'm accessing html again a forward
then i'm accessing html again a forward slash then i'm accessing body
slash then i'm accessing body again a forward slash i'm accessing form
again a forward slash i'm accessing form then in form tag i want to access the
then in form tag i want to access the third input
third input tag how i will write my xml path
tag how i will write my xml path okay this is the xml path expression
okay this is the xml path expression that i discussed before
that i discussed before next it says that it starts with a
next it says that it starts with a single slash
single slash here you can see it is started with a
here you can see it is started with a single slash over here from root element
single slash over here from root element to the desired element
to the desired element next uh let us discuss is advantages and
next uh let us discuss is advantages and disadvantages the advantage of absolute
disadvantages the advantage of absolute xpath is that it identify identifies the
xpath is that it identify identifies the element very fast
element very fast now obviously over here you are writing
now obviously over here you are writing the
the complete path
complete path like we are writing
like we are writing html slash body slash form slash input
html slash body slash form slash input the third index we are writing the
the third index we are writing the complete path because of this it is
complete path because of this it is accessing the element very faster okay
accessing the element very faster okay that is the advantage of absolute x path
that is the advantage of absolute x path whereas the disadvantage now for this
whereas the disadvantage now for this we'll take up an example so that it will
we'll take up an example so that it will be easier for you
be easier for you so this is the page that you have that
so this is the page that you have that is the username and password and the
is the username and password and the login page that you have for that you
login page that you have for that you have written the html syntax right
have written the html syntax right now what if the developer wants to make
now what if the developer wants to make some changes on this page it wants to uh
some changes on this page it wants to uh suppose a developer wants to enter
suppose a developer wants to enter another field
another field of email
of email so
so here it is username password email i
here it is username password email i have written another uh
have written another uh syntax over here that is the input id
syntax over here that is the input id email type text okay so the developer
email type text okay so the developer has entered another uh
has entered another uh text field over here of email
text field over here of email and i have to access the login and i had
and i have to access the login and i had written the xpath before this one right
written the xpath before this one right this is the expert that i had written
this is the expert that i had written before
before so is it possible to access the login
so is it possible to access the login now after making this changes no right
now after making this changes no right this was the previous expert that i had
this was the previous expert that i had written for the login button
written for the login button for that
for that this was the syntax i'm accessing the
this was the syntax i'm accessing the third element of input
third element of input that is the login right over here
that is the login right over here i am accessing the third element of
i am accessing the third element of input which is the email id right it is
input which is the email id right it is the email id that is present over here
the email id that is present over here so this is the biggest disadvantage of
so this is the biggest disadvantage of absolute xpath
absolute xpath that is if there are any changes that is
that is if there are any changes that is made by the developers in the path of
made by the developers in the path of the element then our written expat will
the element then our written expat will no longer work as you saw in that
no longer work as you saw in that example
example i had written the expert for the login
i had written the expert for the login but when the changes were made by the
but when the changes were made by the developers the expert did not work for
developers the expert did not work for the
the login button because at that place the
login button because at that place the third element of input tag was the email
third element of input tag was the email id
id okay
okay so this is the advantages of the
so this is the advantages of the absolute x-path
absolute x-path so now let's discuss about the relative
so now let's discuss about the relative x-path
x-path now a relative x-path is the one where
now a relative x-path is the one where the path starts from the middle of the
the path starts from the middle of the html dom structure of your choice your
html dom structure of your choice your there is no root note there is no
there is no root note there is no desired node you can simply uh start the
desired node you can simply uh start the path where you want to of your choice
path where you want to of your choice wherever you want to start so basically
wherever you want to start so basically it means that it can search for the
it means that it can search for the element anywhere on the web page okay
element anywhere on the web page okay and it starts with a double slash
and it starts with a double slash whereas the absolute x path starts with
whereas the absolute x path starts with a single slash
a single slash it has a syntax and this is the basic
it has a syntax and this is the basic syntax of the relative x path
syntax of the relative x path first we have the double slashes then we
first we have the double slashes then we have the tag name the stack name can be
have the tag name the stack name can be div image input etc anything
div image input etc anything okay then uh we will open the brackets
okay then uh we will open the brackets and then we have the add the rate this
and then we have the add the rate this add the rate is used to select an
add the rate is used to select an attribute we will write the attribute
attribute we will write the attribute name and we will write the value of this
name and we will write the value of this attribute okay for example
attribute okay for example i have written first the two the forward
i have written first the two the forward slashes i need the double forward
slashes i need the double forward slashes
slashes then i need input
then i need input that is the tag name i'll open my
that is the tag name i'll open my brackets at the rate the attribute that
brackets at the rate the attribute that i'm using is id and the value of this
i'm using is id and the value of this attribute is email
attribute is email so this is the basic syntax of xml that
so this is the basic syntax of xml that is the relative xml and this is most
is the relative xml and this is most frequently used as compared to the
frequently used as compared to the absolute xml
absolute xml why we will discuss that later
so the advantages of relative x path the first advantage is that you don't need
first advantage is that you don't need to mention the long x bar the long x bar
to mention the long x bar the long x bar that is the absolute x path is from the
that is the absolute x path is from the root element to the desired element
root element to the desired element right so over here you don't need to
right so over here you don't need to mention this long x path because there
mention this long x path because there is no
is no need to start from the root element you
need to start from the root element you can start
can start middle at you the path can start from
middle at you the path can start from the middle of the html dom structure
the middle of the html dom structure that is of your choice
that is of your choice but the disadvantage is that it will
but the disadvantage is that it will take more time in identifying the
take more time in identifying the element as we are specifying the partial
element as we are specifying the partial path and not the exact exact part
path and not the exact exact part whereas in absolute x path we are
whereas in absolute x path we are specifying the exact path of the element
specifying the exact path of the element over here we are specifying the partial
over here we are specifying the partial path of the elements so that is the
path of the elements so that is the reason why it takes time in processing
reason why it takes time in processing so here we have some of the examples of
so here we have some of the examples of the relative x path like first you can
the relative x path like first you can see i have the two double slashes the
see i have the two double slashes the tag name that i have used is a
tag name that i have used is a then this is the at the rate sign the
then this is the at the rate sign the attribute is hereif and the value of the
attribute is hereif and the value of the attribute that i have given over here
attribute that i have given over here next i have the two double slashes and i
next i have the two double slashes and i have used the image that is the img uh
have used the image that is the img uh tag name then i have the add the rate
tag name then i have the add the rate sign and the attribute that i'm using is
sign and the attribute that i'm using is alt and the value of this is flower so
alt and the value of this is flower so these are some of the examples
these are some of the examples now if you want to access a x part with
now if you want to access a x part with multiple attributes what if we have
multiple attributes what if we have multiple attributes like suppose there
multiple attributes like suppose there might be a
might be a syntax where the name value the name the
syntax where the name value the name the value of the name is similar so what
value of the name is similar so what we'll do is we'll use multiple
we'll do is we'll use multiple attributes we'll use id with that
attributes we'll use id with that because id is never same it is not the
because id is never same it is not the same for every element it is different
same for every element it is different id is unique right so what i'm going to
id is unique right so what i'm going to do is i'm going to use id that is over
do is i'm going to use id that is over here is name and also the name attribute
here is name and also the name attribute that is the name value so by using these
that is the name value so by using these multiple attributes value i can access
multiple attributes value i can access the element more properly right so the
the element more properly right so the syntax of this is tag name or the two
syntax of this is tag name or the two double slashes tag name open bracket at
double slashes tag name open bracket at the rate attribute one is equal to value
the rate attribute one is equal to value one and then the attribute two the value
one and then the attribute two the value two similarly like attribute three value
two similarly like attribute three value three so you can go on
three so you can go on as you wish okay so this is a way of
as you wish okay so this is a way of accessing multiple attributes
accessing multiple attributes in relative x path
in relative x path so now let's study the difference
so now let's study the difference between the absolute x path and the
between the absolute x path and the relative exponent
relative exponent now the absolute x path it contains the
now the absolute x path it contains the complete path from the root element to
complete path from the root element to the desired element as we studied from
the desired element as we studied from the root element that is the html and
the root element that is the html and the desired element that we wanted that
the desired element that we wanted that is the login button we have the
is the login button we have the input tag right the input third index
input tag right the input third index so it contains the complete path from
so it contains the complete path from the root element to the desired element
the root element to the desired element whereas the relative x path
whereas the relative x path is the one where the path starts from
is the one where the path starts from the middle of the html dom structure of
the middle of the html dom structure of your choice you can start from your
your choice you can start from your choice
choice okay
okay it starts with a single forward slash
it starts with a single forward slash whereas over here in later it starts
whereas over here in later it starts with the doubles forward slash
with the doubles forward slash in absolute x path not used more often
in absolute x path not used more often because it selects
because it selects element from the root node
element from the root node whereas the relative x path is used very
whereas the relative x path is used very often because it searches the element
often because it searches the element everywhere at the web page
everywhere at the web page okay
okay next we have in absolute x bar there is
next we have in absolute x bar there is no attribute value over here the syntax
no attribute value over here the syntax that i had shown before
like this is the syntax of the xpath here we have the attribute value right
here we have the attribute value right we are using the value of the attribute
we are using the value of the attribute and the attribute name
and the attribute name whereas in absolute x path there is no
whereas in absolute x path there is no such case there is no attribute value in
such case there is no attribute value in relative we use the attribute and the
relative we use the attribute and the value of it
value of it this is the basic example of the
this is the basic example of the absolute expert and this is the example
absolute expert and this is the example of the relative x path
of the relative x path [Music]
[Music] so this is the difference between the
so this is the difference between the absolute x pi and the relative x part so
absolute x pi and the relative x part so we know x path are of two types but
we know x path are of two types but which one is mostly preferred
which one is mostly preferred obviously the relative x path is mostly
obviously the relative x path is mostly preferred
preferred why
why because if the application is not very
because if the application is not very stable like if the application is not
stable like if the application is not stable and all the attributes are not
stable and all the attributes are not stable
stable so we are not we cannot use the absolute
so we are not we cannot use the absolute expert why because the developer might
expert why because the developer might make changes frequently right it's not
make changes frequently right it's not stable so the developer will make
stable so the developer will make changes the expat will keep on changing
changes the expat will keep on changing so that is the reason why absolute xpath
so that is the reason why absolute xpath is not mostly used by the automation
is not mostly used by the automation testers whereas the relative xpath is
testers whereas the relative xpath is mostly used by the automation testers
mostly used by the automation testers because in relative xpath the attributes
because in relative xpath the attributes used are fixed they are not changing we
used are fixed they are not changing we are not using the root element to the
are not using the root element to the desired element
desired element okay so that is the reason why we use
okay so that is the reason why we use the relative x path and not the absolute
the relative x path and not the absolute x path
x path so in the previous tutorial we learnt
so in the previous tutorial we learnt about the x path what is x path and the
about the x path what is x path and the different types of x path that is the
different types of x path that is the absolute x path and the relative
absolute x path and the relative exponent also we learned the difference
exponent also we learned the difference between the two so in this tutorial we
between the two so in this tutorial we will understand about the x path
will understand about the x path operators and functions
operators and functions so let's get started
so let's get started so previous uh tutorial we learnt about
so previous uh tutorial we learnt about the relative xpath and the absolute
the relative xpath and the absolute expert let's implement that first on our
expert let's implement that first on our intelligent idea id so open your
intelligent idea id so open your intellij idea
so i will create a new java class
java class i'll name it as
i'll name it as selenium
selenium tutorials
tutorials six
okay so all i want to do is this is the
so all i want to do is this is the website like the ebay.com i'll all i
website like the ebay.com i'll all i want to do is i want to uh inspect this
want to do is i want to uh inspect this search box and the search button okay
search box and the search button okay so for that in the previous tutorial i
so for that in the previous tutorial i explained about the crow path plugin
explained about the crow path plugin now we're going to use the selectors hub
now we're going to use the selectors hub plugin see the selectors hub plugin is
plugin see the selectors hub plugin is the advanced version of the crow path as
the advanced version of the crow path as the crow path is not having some of the
the crow path is not having some of the features which this selector hub
features which this selector hub plugin is having so what we'll do is how
plugin is having so what we'll do is how to install is
to install is write
write selectors hub xpath
selectors hub xpath the first link that you get over here
the first link that you get over here i will provide the link in the
i will provide the link in the description box
description box simply just click to add to chrome
and your selectors hub is added to your chrome browser
chrome browser so since we have
so since we have installed our selectors hub plugin xpath
installed our selectors hub plugin xpath on our browsers so i'll just close this
on our browsers so i'll just close this and i'll open it again
so let me inspect this i'll inspect and here you can see we have the
and here you can see we have the selectors hub
selectors hub present over here
okay so now
so now all i want to do is i want to inspect
all i want to do is i want to inspect this search box and the search button i
this search box and the search button i will write the x path for the search box
will write the x path for the search box and the search button the absolute
and the search button the absolute expert as well as a relative expert so
expert as well as a relative expert so let's do it
let's do it okay so i have created this uh selenium
okay so i have created this uh selenium tutorial 6 this is the java class that i
tutorial 6 this is the java class that i have created in my selenium package the
have created in my selenium package the first statement that i have written is
first statement that i have written is to open the chrome browser that is the
to open the chrome browser that is the system.set property in which i have
system.set property in which i have given the key value
given the key value and the value of the that is the path of
and the value of the that is the path of the executable driver
the executable driver next i have written the web driver
next i have written the web driver driver is equal to new chrome driver
driver is equal to new chrome driver next i have to navigate to the url that
next i have to navigate to the url that is the url i have given over here
is the url i have given over here next i am maximizing the window through
next i am maximizing the window through driver.manage.window
okay so these are the three commands which is uh
which is uh same in all the tutorials till now
same in all the tutorials till now you want to locate the search box right
you want to locate the search box right through relative xpath and absolute
through relative xpath and absolute expert let's first do the absolute x
expert let's first do the absolute x path
[Music] okay so simply i'll just write driver
okay so simply i'll just write driver dot find
dot find element
element by dot
by dot x path
x path and i will write the absolute x path
and i will write the absolute x path over here
let me inspect this element here it is and here you can see we have
here it is and here you can see we have the re relative x path we have the id
the re relative x path we have the id name
name class name
class name uh javascript path the absolute xpath
uh javascript path the absolute xpath and the tag name that is given over here
and the tag name that is given over here in selectors hub we have
in selectors hub we have many features there are a lot of
many features there are a lot of features provided in selectors hub as
features provided in selectors hub as compared to the crow path plugin the
compared to the crow path plugin the crowbar plugin is not having that much
crowbar plugin is not having that much of features in it so that is the reason
of features in it so that is the reason why uh selectors hub is mostly used by
why uh selectors hub is mostly used by many automation testers also it supports
many automation testers also it supports the uh shadow dom objects now uh when i
the uh shadow dom objects now uh when i will be explaining about the shadow dome
will be explaining about the shadow dome at that time we will be using it but for
at that time we will be using it but for now uh
now uh let us focus on the absolute path in the
let us focus on the absolute path in the relative expat that we are doing right
relative expat that we are doing right now
now so this is the absolute x bar that we
so this is the absolute x bar that we have i'll simply click on copy
i want to send some command to it so i'll write send keys
i'll write send keys and i'll write
and i'll write t-show
okay so let's run this
let's run this so let's run this
so let's run this i'll simply click on run
chrome browser is launched it's navigated
it's navigated the browser is maximized
the browser is maximized and here you can see on the search box
and here you can see on the search box we have t-shirts written over here okay
so next uh what i want to do is i want to inspect this element that is i want
to inspect this element that is i want to click on the search button okay so i
to click on the search button okay so i will inspect this element
and here you can see we have the absolute xpath as well as the relative
absolute xpath as well as the relative expat we will choose the absolute xpath
expat we will choose the absolute xpath but
here we'll write driver dot find element
dot find element by dot x path and i will write my
by dot x path and i will write my absolute x path
absolute x path over here
over here and what i want to do is i want to click
and what i want to do is i want to click right so i will right click
so here it is i am sending some command to the search box that is the t-shirt
to the search box that is the t-shirt command and then i am clicking on the
command and then i am clicking on the search button
search button so let's run this
chrome browser is launched it's navigated the browser is
it's navigated the browser is maximized t-shirts and here it's clicked
okay so it's working properly
so it's working properly now let's do with a relative xpath
now let's do with a relative xpath i'll commend this
okay so now we'll do it relative
relative xpath
xpath i'll write driver
i'll write driver dot find element
dot find element by dot
by dot x path and i'm going to mention my
x path and i'm going to mention my relative x path over here
relative x path over here so as for the search box
so as for the search box here it is we have the relative x path
here it is we have the relative x path which is written over here
which is written over here and simply copy this
and simply copy this and paste it over here okay so be
and paste it over here okay so be careful with this syntax we have only
careful with this syntax we have only the single quote over here there is no
the single quote over here there is no double quote because java does not
double quote because java does not support double quotes so if you mention
support double quotes so if you mention double quote over here
double quote over here it will not support
it will not support here you see right it's in red color so
here you see right it's in red color so that's the reason why java does not
that's the reason why java does not support
support double uh inside double quotes another
double uh inside double quotes another double quote so that's the reason why
double quote so that's the reason why we're writing with single quotes okay
we're writing with single quotes okay so be careful with that
so be careful with that now this is the relative expert for the
now this is the relative expert for the search box and what i want to do is i
search box and what i want to do is i want to send some key right so i will
want to send some key right so i will write
so i'll write shirts for men okay next i want is i want to
next i want is i want to inspect the
inspect the search button right for that i'll write
search button right for that i'll write fine element
fine element by dot x path
this is the search button let me inspect it
it and here you can see we have the
and here you can see we have the relative expert given over here right so
relative expert given over here right so i'll copy it
i'll copy it paste it over here and what action do i
paste it over here and what action do i need to perform is i want to click on
need to perform is i want to click on that button right so i will write click
let's see if this runs chrome browser is launched
it's navigated and it's maximized it's written shirts
and it's maximized it's written shirts for men
and here it is okay so it's working properly
okay so it's working properly so this is how you can inspect element
so this is how you can inspect element through absolute expat and the relative
through absolute expat and the relative x path ah the difference between the
x path ah the difference between the absolute expired and the relative expert
absolute expired and the relative expert we studied about that in the previous
we studied about that in the previous tutorial also their advantages and
tutorial also their advantages and disadvantages
disadvantages okay so in this tutorial mainly we will
okay so in this tutorial mainly we will understand about the
understand about the xpath operators and their functions
so the first thing is or operator now when we implement this uh practically at
when we implement this uh practically at that time you will understand it very uh
that time you will understand it very uh properly so first let us understand the
properly so first let us understand the syntax of it as in the previous tutorial
syntax of it as in the previous tutorial i explained about the expert with
i explained about the expert with multiple attributes
multiple attributes here you can see
here you can see that is the two slashes over here the
that is the two slashes over here the tag name that we want that is input a or
tag name that we want that is input a or any of the tag name at the rate
any of the tag name at the rate attribute 1 is equal to value 1 at the
attribute 1 is equal to value 1 at the rate attribute 2 is equal to value 2 and
rate attribute 2 is equal to value 2 and so on this is how we will write x bar
so on this is how we will write x bar with multiple attributes now with the
with multiple attributes now with the help of these multiple attributes we are
help of these multiple attributes we are inserting some of the operators of x bar
inserting some of the operators of x bar that is the or operator and the and
that is the or operator and the and operator
operator like here you can see we have the two
like here you can see we have the two slashes over here the tag name that
slashes over here the tag name that we're using that is the input
we're using that is the input at the rate id the attribute that we are
at the rate id the attribute that we are using is id and the value of it is the
using is id and the value of it is the search underscore query
search underscore query or the or operator which i have written
or the or operator which i have written over here
over here then the second attribute that i am
then the second attribute that i am using at the rate name
using at the rate name and the value of it is search okay so
and the value of it is search okay so this is how we will write the syntax
this is how we will write the syntax with the operator in equilibrium x path
with the operator in equilibrium x path now we will implement this method and
now we will implement this method and then you will understand this table
so i will just comment this
okay so now what i want is i will inspect
so now what i want is i will inspect this element and i'll uh try to send
this element and i'll uh try to send some of the keys of it like i'll write
some of the keys of it like i'll write t-shirts for men over here so let's see
t-shirts for men over here so let's see if the element is identified or not
if the element is identified or not okay i'll click on inspect
okay i'll click on inspect okay so in this syntax here you can see
okay so in this syntax here you can see we have the id attribute as well as the
we have the id attribute as well as the name attribute present over here
name attribute present over here okay so first
okay so first let me write
let me write driver
driver dot
dot find element
find element by
by dot x path
dot x path and here i will write my relative
and here i will write my relative x path so first the two slashes
x path so first the two slashes the tag name that i want is input
the tag name that i want is input open bracket
open bracket first i am going to write
first i am going to write at the rate
at the rate id
id so the value of the id
is this here you can see so let me copy this
so let me copy this next i'm going to write or
then i'm going to write add the rate name attribute
that is this i will just simply copy it
i will just simply copy it paste it over here
paste it over here dot
dot send keys and whatever keys i want to
send keys and whatever keys i want to send is short
send is short for
for men
men and let's see whether we can locate this
and let's see whether we can locate this element or not
so a chrome browser is launched it's navigated
it's navigated it's maximized and here you can see
it's maximized and here you can see shirts for men that means this search
shirts for men that means this search box is located through our operator
box is located through our operator okay
okay so now here you can see
this a part the id part at the rate id is the a
is the a at the rate name is the b part right now
at the rate name is the b part right now if both the elements are true that means
if both the elements are true that means the return the element is identified and
the return the element is identified and it returns both the element right now
it returns both the element right now what if
what if my first element is true and the second
my first element is true and the second element is false it returns a so let's
element is false it returns a so let's check this out
that means at the rate id is equal to this value is correct whereas this value
this value is correct whereas this value is not correct now let's see what
is not correct now let's see what happens
happens whether we are able to locate the
whether we are able to locate the element or not
element or not so i click on run
my browser is navigated
navigated it's maximize and here you can see
it's maximize and here you can see shirts for men
shirts for men the search box is inspected it is
the search box is inspected it is identified
identified even though if my name attribute the
even though if my name attribute the value of the name attribute is not
value of the name attribute is not correct okay
correct okay now what if my ad id value is not
now what if my ad id value is not correct like if i write this gh
correct like if i write this gh let's see whether we can identify the
let's see whether we can identify the element or not
my chrome browser is launched it's navigated
it's navigated it's maximized
it's maximized and here you can see shirts for men
and here you can see shirts for men it's identified
it's identified okay
okay now what if the id value is wrong and
now what if the id value is wrong and even the name value is wrong
even the name value is wrong let's see if the element is identified
let's see if the element is identified or not
so our chrome browser is navigated and it's maximized
and here you can see there is no element over here there is no key sent over here
over here there is no key sent over here that is the shirts for men
that is the shirts for men why because my id value as well as the
why because my id value as well as the name value is wrong okay
name value is wrong okay so this is what the
so this is what the or operator is
or operator is if my a element that is the id value
if my a element that is the id value is wrong as well as the name attribute
is wrong as well as the name attribute value is wrong that means it's not the
value is wrong that means it's not the same as it is specified in the html dom
same as it is specified in the html dom structure the element will not be
structure the element will not be identified
identified whereas if my id value is wrong but my
whereas if my id value is wrong but my name value is correct the element is
name value is correct the element is identified similarly if my a value that
identified similarly if my a value that is the id value is right whereas my name
is the id value is right whereas my name value is wrong
value is wrong still the element is identified and if
still the element is identified and if both are right the element is identified
both are right the element is identified but if both are wrong the element is not
but if both are wrong the element is not identified so this is all about the or
identified so this is all about the or operator
operator now let's check out the and operator
now let's check out the and operator okay it's the same as it is or only the
okay it's the same as it is or only the rules are bit different you will
rules are bit different you will understand that practically
understand that practically so we are testing for and operators so
so we are testing for and operators so i'll just write and over here
i'll just write and over here let's see so the id value is same and
let's see so the id value is same and the name value is also correct so let's
the name value is also correct so let's see if it is inspected the element is
see if it is inspected the element is inspected or not let me comment this
inspected or not let me comment this okay
okay all right
when chrome browser's launched it's navigated it's maximized and here you
navigated it's maximized and here you can see the
can see the shirts for men
shirts for men the search box is inspected as well as
the search box is inspected as well as the command is sent that is the shirts
the command is sent that is the shirts for women so this means this uh line
for women so this means this uh line this
this driver.fine element this function that
driver.fine element this function that we have written works well okay now what
we have written works well okay now what if if i just
if if i just write the id value wrong whereas the
write the id value wrong whereas the name value the value of name attribute
name value the value of name attribute is correct okay so let's see if the
is correct okay so let's see if the element is identified or not
element is identified or not so my chrome browser is launched
so my chrome browser is launched it's navigated
it's navigated it's maximized
okay there is no command sent over here
command sent over here okay so if my id is wrong
okay so if my id is wrong and my name is right that means the
and my name is right that means the element is not identified
element is not identified what if my id value is correct whereas
what if my id value is correct whereas the name value is wrong
the name value is wrong let's see if the element is identified
let's see if the element is identified or not
my chrome browser is launched it's navigated
it's navigated and it's maximized
okay so here you can see that my search box is not
box is not identified and there is no command sent
identified and there is no command sent over here
over here so your element cannot be identified if
so your element cannot be identified if the id value is right and the name value
the id value is right and the name value is wrong as well as the id value is
is wrong as well as the id value is right wrong and the name value is right
right wrong and the name value is right both of the ways the i
both of the ways the i the element is not found what if
the element is not found what if both of them are wrong
both of them are wrong let's see
let's see let me inspect it
let me inspect it click on run
click on run chrome browser is launched
chrome browser is launched it's
it's navigated it's maximized
navigated it's maximized and here you can see there is no command
and here you can see there is no command sent over here
sent over here okay
if the a element that is the id attribute is having the wrong value
attribute is having the wrong value as well as the name attribute is having
as well as the name attribute is having the wrong value the element is not
the wrong value the element is not identified
identified similarly if the a attribute that is the
similarly if the a attribute that is the id attribute is having the wrong value
id attribute is having the wrong value and the name attribute is having the
and the name attribute is having the right value still the element is not
right value still the element is not identified
identified if the a attribute is having the correct
if the a attribute is having the correct value whereas the b attribute is having
value whereas the b attribute is having the wrong value still the element is not
the wrong value still the element is not identified
identified in case of and operator the element is
in case of and operator the element is only identified if the id attribute is
only identified if the id attribute is correct as well as the name attribute
correct as well as the name attribute value is correct only then the element
value is correct only then the element is identified so that is the difference
is identified so that is the difference between the and operator and the or
between the and operator and the or operator like here you can see
operator like here you can see the element is identified in all the
the element is identified in all the cases except if both the uh attribute
cases except if both the uh attribute values are wrong okay whereas over here
values are wrong okay whereas over here it is
it is the element is identified in only one
the element is identified in only one case that is both the id as well as the
case that is both the id as well as the name attribute value should be correct
name attribute value should be correct that is it should be the same as it is
that is it should be the same as it is mentioned in the html dom structure
mentioned in the html dom structure so this is the difference between the or
so this is the difference between the or operator and the and operator
operator and the and operator so the next function that we're going to
so the next function that we're going to study about is the contains function
study about is the contains function now the contains is used to identify an
now the contains is used to identify an element all the functions that we
element all the functions that we studied till now of x path are used to
studied till now of x path are used to identify an element
identify an element when we are familiar with some part of
when we are familiar with some part of the attribute value of an element
the attribute value of an element now this means that when we are familiar
now this means that when we are familiar with some part of the attributes value
with some part of the attributes value that is for example let me show you the
that is for example let me show you the normal syntax of the relative x bar that
normal syntax of the relative x bar that we write is this right
we write is this right two
two two slashes the tag name add the rate id
two slashes the tag name add the rate id and the value like over here you can see
and the value like over here you can see two slashes input at the rate id and the
two slashes input at the rate id and the value that i have written is the first
value that i have written is the first name
name now what if you want to use the contains
now what if you want to use the contains method when we are using the contains
method when we are using the contains method we will write add the rate id
method we will write add the rate id comma first that is only the partial
comma first that is only the partial text i will write in contains method i
text i will write in contains method i don't need to write the full text
don't need to write the full text so this is a feature of contains
the next function that we're going to study is the starts with function now
study is the starts with function now see all these functions that we are
see all these functions that we are studying they are used dynamically for
studying they are used dynamically for dynamic uh elements they are used now
dynamic uh elements they are used now what are dynamic elements there are two
what are dynamic elements there are two types of elements one is dynamic and one
types of elements one is dynamic and one is static static elements are elements
is static static elements are elements whose attributes value does not change
whose attributes value does not change the value of the attribute does not
the value of the attribute does not change
change whereas the dynamic elements are the
whereas the dynamic elements are the elements whose attribute value changes
elements whose attribute value changes on refresh or any of the operation of
on refresh or any of the operation of the web page like if we click on that
the web page like if we click on that element the value changes
element the value changes for example let us take up the start and
for example let us take up the start and the stop button like this is the button
the stop button like this is the button if i click on start
if i click on start the function will start
the function will start but after start the button changes to
but after start the button changes to stop
stop and when i click on stop
and when i click on stop the function will stop and the button
the function will stop and the button will change the value will change to
will change the value will change to start so this is how this this is what
start so this is how this this is what is the dynamic working of the
is the dynamic working of the uh
uh of the elements on the web page now for
of the elements on the web page now for example like over here you can see we
example like over here you can see we have the button like start and the stop
have the button like start and the stop if i want to inspect the start button i
if i want to inspect the start button i want to uh
want to uh identify the start element what i'm
identify the start element what i'm going to do is i'm going to write slash
going to do is i'm going to write slash input two slashes input at the rate id
input two slashes input at the rate id is equal to start
is equal to start this will identify this will locate the
this will identify this will locate the start button only and not the stop
start button only and not the stop button
button because after clicking on start
because after clicking on start the value is changing to stop right so
the value is changing to stop right so it will only identify the start button
it will only identify the start button what about stop
what about stop so for that i have to write input at the
so for that i have to write input at the rate id is equal to stop over here also
rate id is equal to stop over here also it is identifying only the stop button
it is identifying only the stop button and not the start button
and not the start button so in this case we will use the start
so in this case we will use the start smith operation
smith operation now here you can see there are two
now here you can see there are two things there are two words in common
things there are two words in common right the s t
right the s t s and t these are the two words that are
s and t these are the two words that are in common over here so what i'm going to
in common over here so what i'm going to do is i'm going to use a starts with
do is i'm going to use a starts with function i'm going to write starts with
function i'm going to write starts with either rate id and sd
either rate id and sd in this case it will detect the start
in this case it will detect the start operation as well as the stop operation
operation as well as the stop operation so this is the advantage of start swipe
so this is the advantage of start swipe like here you can
like here you can like here you can see
like here you can see start with find the element whose
start with find the element whose attribute value changes on refresh or
attribute value changes on refresh or any operation on the web page like
any operation on the web page like clicking the uh in the element on the
clicking the uh in the element on the web page
web page now in this expression matching the
now in this expression matching the starting text of the attribute used to
starting text of the attribute used to find the element whose attribute changes
find the element whose attribute changes dynamically
dynamically here's the attribute value this is the
here's the attribute value this is the attribute value right that start and the
attribute value right that start and the stop this attribute value is changing
stop this attribute value is changing dynamically right
dynamically right so this is what we're going to do we are
so this is what we're going to do we are going to match the starting text of the
going to match the starting text of the attribute values this is the starting
attribute values this is the starting text which is the similarity
text which is the similarity so always keep in mind that the
so always keep in mind that the starting value of the attribute should
starting value of the attribute should be similar
be similar then only starts with function will work
then only starts with function will work we can also find element whose attribute
we can also find element whose attribute value is static which does not change
value is static which does not change but this works uh properly with dynamic
but this works uh properly with dynamic functions okay
so let's implement this first now this is the page this is the element
now this is the page this is the element that i want to inspect
i'll click on inspect and here it is so what i'm going to do is i'm going to
what i'm going to do is i'm going to write the
write the x path over here okay
x path over here okay for contains method
for contains method so let me write two slashes the tag name
so let me write two slashes the tag name input
then contains open brackets
open brackets the rate i'll use
i'll use name let me use name attribute so i'll write
so i'll write name
name comma
comma single quotes
underscore nkw
nkw here you can see
here you can see this value
this value let me copy this
and close the bracket close the back
close the back and here you can see we have one element
and here you can see we have one element matching which shows one element
matching which shows one element matching this element is matching it is
matching this element is matching it is highlighted right so this is the element
highlighted right so this is the element which is matched over here now if i'm
which is matched over here now if i'm using contains as i said i can use
using contains as i said i can use partial text right so what i'll do i'll
partial text right so what i'll do i'll just remove w
just remove w and still you can see one element
and still you can see one element matching
matching and still you can see one element
and still you can see one element matching i remove i remove the k as well
matching i remove i remove the k as well so
so let's see if it is detecting this
let's see if it is detecting this element or not i will copy this
right driver dot
find element by dot x path
by dot x path and i will mention this
and i want to send some
send some value to it so i'll write
value to it so i'll write shirts for
shirts for kids
kids my chrome browser is launched
it's maximized and here you can see we have the value written away shirts for
have the value written away shirts for kids so this means that the search box
kids so this means that the search box that i have inspected over here through
that i have inspected over here through contains method is working properly okay
contains method is working properly okay we can locate the element over here so
we can locate the element over here so this is how we will use contains method
this is how we will use contains method now if i use
now if i use starts with
starts with i'll just simply remove this contains
i'll just simply remove this contains and write
and write starts with
starts with and here you can see
and here you can see uh so since uh
uh so since uh selectors hubs gives us the feature of
selectors hubs gives us the feature of writing the x path over here as well in
writing the x path over here as well in the uh expired the text box so i have
the uh expired the text box so i have written a input starts with at the rate
written a input starts with at the rate name and here you can see it is starting
name and here you can see it is starting with underscore n right so let me write
with underscore n right so let me write underscore
underscore and here you can see we have one element
and here you can see we have one element matching now what if i remove n
matching now what if i remove n and here you can see we have three
and here you can see we have three elements matching which is matching to
elements matching which is matching to underscore you can see
underscore you can see the uh three elements are given over
the uh three elements are given over here the first element is over here this
here the first element is over here this is the second element and this is the
is the second element and this is the third element
third element since we are inspecting this third
since we are inspecting this third element so i'll just include n see it
element so i'll just include n see it doesn't matter where your what type of
doesn't matter where your what type of value you're writing over here
value you're writing over here these functions are used only for
these functions are used only for dynamically functions now in the next
dynamically functions now in the next tutorial when you learn about the
tutorial when you learn about the advanced x path there you will see many
advanced x path there you will see many dynamic elements so at that point we
dynamic elements so at that point we will use starts with metal okay
will use starts with metal okay i'll just copy this element
i'll just copy this element and let's see if it's working well or
and let's see if it's working well or not
not driver dot
driver dot fine element
fine element y dot x path
y dot x path and here i will include the element
and here i will include the element now let me send some keys
now let me send some keys t-shirts for
kids let me comment this
let me comment this and let's see if it's working well or
and let's see if it's working well or not
so our chrome browser is launched it's navigated
it's navigated and
and it's maximized and here you can see
it's maximized and here you can see t-shirts for kids this means that my
t-shirts for kids this means that my search box the element that i want to
search box the element that i want to inspect that is the search box is
inspect that is the search box is inspected through
inspected through these starts with method okay see i'm
these starts with method okay see i'm here i'm just showing the demo of using
here i'm just showing the demo of using these functions that how you can use
these functions that how you can use these functions
the next method that we're going to understand is the
understand is the the next function that we're going to
the next function that we're going to study is the text function
study is the text function now see text is an inbuilt function of
now see text is an inbuilt function of the selenium webdriver and it is
the selenium webdriver and it is frequently used and it is one of the
frequently used and it is one of the most popular expat function that is used
most popular expat function that is used and it is basically used to locate
and it is basically used to locate elements the elements that we want to
elements the elements that we want to locate right based on the text of the
locate right based on the text of the web element like here you can see we
web element like here you can see we have the user id
have the user id and the element that i want to locate
and the element that i want to locate this is the text box that i want to look
this is the text box that i want to look at the text of the web element the text
at the text of the web element the text of the web element is the user id over
of the web element is the user id over here by using this this text i am going
here by using this this text i am going to identify this web element okay this
to identify this web element okay this is what text function is
is what text function is over here like you can see uh like if i
over here like you can see uh like if i inspect this element this is the element
inspect this element this is the element that i'm inspecting we have the td tag
that i'm inspecting we have the td tag inside the tr tag we have the td a line
inside the tr tag we have the td a line is equal to right and the text that is
is equal to right and the text that is used that is a user id so if i want to
used that is a user id so if i want to inspect this element how i am going to
inspect this element how i am going to write is the two slashes td
write is the two slashes td the text function the text the value of
the text function the text the value of the text function is the user id this is
the text function is the user id this is how i'm going to write the text function
how i'm going to write the text function okay so let's uh
okay so let's uh do this let's
do this let's do the demo of this
do the demo of this i'll comment this
i'll comment this so this is the cell link that i want to
so this is the cell link that i want to click on so what i'm going to do is i'm
click on so what i'm going to do is i'm going to inspect this element
going to inspect this element and i'll write the x path over here
and i'll write the x path over here the tag that we're using is the a tag
the tag that we're using is the a tag it's a link
it's a link so a tag and i'm going to write text
so a tag and i'm going to write text here you can see
here you can see okay so here we can see that is the one
okay so here we can see that is the one element matching so i'm going to copy
element matching so i'm going to copy this
this x path
x path and i'll paste it over here that'll
and i'll paste it over here that'll write driver
write driver dot find element
dot find element by dot
by dot x path
x path paste it over here and the operation
paste it over here and the operation that i want to perform is i want to
that i want to perform is i want to click on this link okay
click on this link okay so let's see
it's navigated and it's maximized and here you can see
and it's maximized and here you can see the cell
the cell link is clicked okay
now suppose if i want to use the contains
contains and the text method both of them i'll
and the text method both of them i'll write contains
open bracket then i'll write text function
function comma
comma then i'll write
then i'll write a cell
here you can see we have six elements that is matching it
that is matching it sell
sell sell
sell selling
selling then we have saved sellers
then we have saved sellers then sell
then sell sellers information center seller
sellers information center seller information center now see
information center now see here you can see we have used the
here you can see we have used the contains method when we were using the
contains method when we were using the text method only one element was
text method only one element was identified but when we are using the
identified but when we are using the contains method the six elements are
contains method the six elements are matching this means the cell this cell
matching this means the cell this cell word that we're using
word that we're using see here i have used the contains method
see here i have used the contains method if i'm using contains method i'm finding
if i'm using contains method i'm finding six elements
six elements when i was using the text method only i
when i was using the text method only i found only one element matching whereas
found only one element matching whereas if i'm using the contains method there
if i'm using the contains method there are six elements that is matching over
are six elements that is matching over here why
here why because in all these matching elements
because in all these matching elements there are some uh words at the cell like
there are some uh words at the cell like over here we have the cell we have
over here we have the cell we have selling we have said sellers we have
selling we have said sellers we have sell over here again we have the seller
sell over here again we have the seller information center then we have the
information center then we have the seller information center
seller information center so if you're using contains and text so
so if you're using contains and text so this is the difference
this is the difference whereas if i use
whereas if i use starts with over here
there are three elements matching over here here you can see we have sell
here here you can see we have sell seller
seller seller information center there are
seller information center there are three elements that is matching to
three elements that is matching to starts with so this is how you can use
starts with so this is how you can use text function with all the functions
text function with all the functions that i have explained over here which
that i have explained over here which contains start and starts with okay so
contains start and starts with okay so uh
uh but the only difference will be that
but the only difference will be that that we will find multiple elements
that we will find multiple elements through these
through these if we use starts with with text and if
if we use starts with with text and if we use the contains with text
we use the contains with text so
so these were the functions that we studied
these were the functions that we studied let's see the final conclusion of it
let's see the final conclusion of it which function to use when
which function to use when so when do we use contains method in
so when do we use contains method in expert
expert we will use the contains method if you
we will use the contains method if you know the partial constant visible text
know the partial constant visible text or attribute now what is this partial
or attribute now what is this partial constant visible text partial constant
constant visible text partial constant visible text means that if there is any
visible text means that if there is any text like suppose there is an element
text like suppose there is an element which you want to identify
which you want to identify there is a text for it right that is
there is a text for it right that is what we are using in contains method
what we are using in contains method like here you can see
like here you can see the contains method the text which we
the contains method the text which we are using we are using the partial
are using we are using the partial constant text this first is the constant
constant text this first is the constant text even name is the constant text it
text even name is the constant text it contains method and the starts method is
contains method and the starts method is used dynamically
used dynamically so we will use only the words that are
so we will use only the words that are constant
constant okay similarly goes with start with over
okay similarly goes with start with over here the words that are constant is s
here the words that are constant is s and t whereas the other words are
and t whereas the other words are changing right because start
changing right because start as a as we are starting the button it is
as a as we are starting the button it is changing to stop so that value is
changing to stop so that value is changing dynamically okay
so we will use the contains method in x path if you know the partial constant
path if you know the partial constant visible text it should be constant it
visible text it should be constant it should not be dynamically okay
should not be dynamically okay next we will use the starts with method
next we will use the starts with method if you know the initial partial constant
if you know the initial partial constant visible text or the attribute the
visible text or the attribute the initial partial constant text means that
initial partial constant text means that like over here
like over here there is an initial constant text right
there is an initial constant text right that is the st
that is the st you are also st rest all the words are
you are also st rest all the words are changing okay so the partial initial
changing okay so the partial initial constant text is used in starts with
next we can use the contains method and the starts with method with absolute
the starts with method with absolute text or attribute also this means that
text or attribute also this means that we can write
the first name as well similarly for
similarly for uh
uh start with we can write start or stop as
start with we can write start or stop as well but the only problem will be that
well but the only problem will be that it will identify that element only for
it will identify that element only for starts with okay
next we can you use the text method in xpath if you're aware of the absolute
xpath if you're aware of the absolute visible text now here in the text method
visible text now here in the text method we cannot write the partial text like
we cannot write the partial text like over here you can see you cannot use
over here you can see you cannot use text method with the partial text like
text method with the partial text like in the contains method we were writing
in the contains method we were writing the partial text right
the partial text right whereas in text method we are not
whereas in text method we are not allowed to use the partial text like
allowed to use the partial text like over here we were
over here we were identifying the element cell right we
identifying the element cell right we were clicking the element cell in the
were clicking the element cell in the demo now if i write sel only it will not
demo now if i write sel only it will not identify
identify if you're using the text method but in
if you're using the text method but in contains method it will identify okay so
contains method it will identify okay so this is the difference between the two
this is the difference between the two next we cannot make use of starswith
next we cannot make use of starswith method if the initial text is constantly
method if the initial text is constantly changing now for example
changing now for example this st word is changing constantly now
this st word is changing constantly now suppose just imagine we have a button
suppose just imagine we have a button name activated and deactivated
name activated and deactivated the if you're clicking on activate
the if you're clicking on activate button the process is activated and the
button the process is activated and the value of that button is changing to
value of that button is changing to deactivate so the first words are
deactivate so the first words are changing right so in that case you
changing right so in that case you cannot use starts with function
cannot use starts with function so this is the conclusion of the entire
so this is the conclusion of the entire uh tutorial that we learned that is the
uh tutorial that we learned that is the contains whether the starts with method
contains whether the starts with method the text method then now we have learnt
the text method then now we have learnt uh so much about xpath we have learnt
uh so much about xpath we have learnt what is x path what are the different
what is x path what are the different types of x bar that is the relative x
types of x bar that is the relative x path the absolute x path the difference
path the absolute x path the difference between the relative and x absolute x
between the relative and x absolute x bar the functions of x bar that is the
bar the functions of x bar that is the contains the starts with the text method
contains the starts with the text method so uh this is not all about expert the
so uh this is not all about expert the main part about xpath is the advanced
main part about xpath is the advanced expired functions that we are going to
expired functions that we are going to study
study that is uh this this is the graph that
that is uh this this is the graph that we're going to study in the next
we're going to study in the next tutorial that is the xpath access in
tutorial that is the xpath access in which uh we have the uh ancestors we
which uh we have the uh ancestors we have the parent we have the child we
have the parent we have the child we have the following siblings we have the
have the following siblings we have the preceding siblings so uh this entire
preceding siblings so uh this entire thing we're going to study in the html
thing we're going to study in the html dom structure and we will also do the
dom structure and we will also do the demo of it so in the previous tutorial
demo of it so in the previous tutorial we learnt about the xpath
we learnt about the xpath operators and also the expert functions
operators and also the expert functions as well as we learnt about the different
as well as we learnt about the different types of xpath that is the relative x
types of xpath that is the relative x path and the active expat the different
path and the active expat the different types of locators also we have studied
types of locators also we have studied the id name the css selector link text
the id name the css selector link text and everything so in this tutorial we
and everything so in this tutorial we will learn about the advanced xpath with
will learn about the advanced xpath with their access method
their access method in which we will cover what is the xpath
in which we will cover what is the xpath axis and why do we use this x-path axis
axis and why do we use this x-path axis also we will understand the different
also we will understand the different types of x-path axis and the
types of x-path axis and the relationship with their nodes this is
relationship with their nodes this is the most important thing that we need to
the most important thing that we need to understand
understand next we are going to understand their
next we are going to understand their syntax their descriptions and also we
syntax their descriptions and also we will implement it practically we will
will implement it practically we will automate two websites let me show you
automate two websites let me show you those
those first is this website we will automate
first is this website we will automate this table as well as we will automate
this table as well as we will automate this form
this form so let's get started so the first thing
so let's get started so the first thing that we need to understand is what is
that we need to understand is what is the xpath access
the xpath access now the xpath axis are those axes that
now the xpath axis are those axes that is used to search for multiple nodes in
is used to search for multiple nodes in the xml document for the current node
the xml document for the current node context now what is this current node
context now what is this current node context we will understand while
context we will understand while studying the relationship of nodes now
studying the relationship of nodes now why are we using the xpath access if we
why are we using the xpath access if we have locators like the id name class
have locators like the id name class link text and all these locators are
link text and all these locators are there still we are using the xpath
there still we are using the xpath access why see in the previous tutorial
access why see in the previous tutorial i explained about some of the expat
i explained about some of the expat functions right that is the contains
functions right that is the contains method and the text method and the
method and the text method and the startswith method so even after using
startswith method so even after using those expert functions we cannot
those expert functions we cannot identify the element that is the that is
identify the element that is the that is when we can use the xpath access
when we can use the xpath access so what to do when the expat functions
so what to do when the expat functions fail to identify the elements in that
fail to identify the elements in that case we will use the xpath access along
case we will use the xpath access along with the xpath functions like the expert
with the xpath functions like the expert functions can be contact contains text
functions can be contact contains text start with we can use those functions as
start with we can use those functions as well as the xpath access also we can use
well as the xpath access also we can use those selectors like the id name class
those selectors like the id name class link text css selectors these locators
link text css selectors these locators can also be used okay
can also be used okay so this is what expert access is and why
so this is what expert access is and why do we use xpath access
do we use xpath access next there are different types of expat
next there are different types of expat access like we have the child we have
access like we have the child we have the parent we have following proceeding
the parent we have following proceeding following sibling preceding sibling and
following sibling preceding sibling and sister descendants we will understand
sister descendants we will understand these terms in detail
these terms in detail now here it comes
now here it comes this is the relationship of note okay
this is the relationship of note okay this is one of the most important uh
this is one of the most important uh thing we need to learn in x-path access
thing we need to learn in x-path access you need to remember you need to
you need to remember you need to understand this relationship of note
understand this relationship of note picture
picture and uh so just have a look at this
and uh so just have a look at this picture properly and see this topic is a
picture properly and see this topic is a bit difficult to understand but once you
bit difficult to understand but once you get a hang of this relationship of nodes
get a hang of this relationship of nodes uh it will be very easier for you to
uh it will be very easier for you to locate the elements in the dom html
locate the elements in the dom html structure okay so now uh let's start
structure okay so now uh let's start from this node that is a self node now i
from this node that is a self node now i would suggest you that uh take this
would suggest you that uh take this relationship nodes in your family
relationship nodes in your family context as in when you study your family
context as in when you study your family tree that is the ancestor parents your
tree that is the ancestor parents your siblings your children your descendants
siblings your children your descendants so when you take take in those contexts
so when you take take in those contexts when you take in those family terms it
when you take in those family terms it will be very easy for you to understand
will be very easy for you to understand this relationship okay
this relationship okay because there are many different uh
because there are many different uh keywords that we need to understand the
keywords that we need to understand the ancestor the parent the child the
ancestor the parent the child the preceding sibling the following sibling
preceding sibling the following sibling so to get a hang of it just keep
so to get a hang of it just keep yourself over here and just imagine your
yourself over here and just imagine your family tree
family tree so here uh this is you and this is the
so here uh this is you and this is the self element okay
self element okay each and every node present over here is
each and every node present over here is an element okay so this is self element
an element okay so this is self element so what will be your parent element the
so what will be your parent element the one about the self element is the parent
one about the self element is the parent element that here you can see is three
element that here you can see is three this is your parent element
this is your parent element and your ancestor is one now if you keep
and your ancestor is one now if you keep yourself over here who will be your
yourself over here who will be your ancestors your parents parents will be
ancestors your parents parents will be your ancestor right so in this case one
your ancestor right so in this case one is your ancestor so now uh this is
is your ancestor so now uh this is yourself element three is the parent one
yourself element three is the parent one is the ancestor
is the ancestor now if you keep yourself over here your
now if you keep yourself over here your children that is the 9 10 11 12 and 13
children that is the 9 10 11 12 and 13 these are the child notes that are
these are the child notes that are present over here okay
present over here okay this is you
this is you the one above you is your parent and
the one above you is your parent and your parents parent is your ancestor
your parents parent is your ancestor and your children are your child notes
and your children are your child notes that is the 9 10 11 12 and 13. these are
that is the 9 10 11 12 and 13. these are your child notes okay
your child notes okay coming to the next term that is a
coming to the next term that is a descendant now what are those
descendant now what are those descendants
descendants descendant notes are
descendant notes are children's children as well as the
children's children as well as the children
children okay
okay that means
that means descending will be your 9
descending will be your 9 10 11 12 13
10 11 12 13 14 15 16 17 and 18.
14 15 16 17 and 18. keeping yourself over here your children
keeping yourself over here your children and your children's children will be
and your children's children will be your descendants okay
your descendants okay so what did we understand till now
so what did we understand till now keeping yourself over here the one the
keeping yourself over here the one the element above you is the parent parent's
element above you is the parent parent's parent is the ancestor that is the one
parent is the ancestor that is the one and your child nodes that is your
and your child nodes that is your children are your child notes
children are your child notes children's childrens are your descendant
children's childrens are your descendant nodes okay
nodes okay now let's go to the preceding and the
now let's go to the preceding and the following these are the two uh terms
following these are the two uh terms that are left
that are left now the preceding siblings and the
now the preceding siblings and the following siblings okay
following siblings okay now your let's take in terms of family
now your let's take in terms of family tree this is yourself keep yourself over
tree this is yourself keep yourself over here okay
here okay now just imagine that your brothers and
now just imagine that your brothers and sisters
sisters that are elder to you okay is your
that are elder to you okay is your preceding sibling
preceding sibling and your brothers and sisters that are
and your brothers and sisters that are younger to you are your following
younger to you are your following siblings okay this is what is following
siblings okay this is what is following siblings and preceding siblings
siblings and preceding siblings now coming to proceeding and following
now coming to proceeding and following now your following means the elements
now your following means the elements that come after the current html tag the
that come after the current html tag the current html tag means the self tag the
current html tag means the self tag the elements that come after the seller self
elements that come after the seller self tag is the following tag which includes
tag is the following tag which includes the following siblings also
the following siblings also whereas preceding is the elements that
whereas preceding is the elements that come before the self tag
come before the self tag which includes the preceding siblings as
which includes the preceding siblings as well see when we practically implement
well see when we practically implement this it will be more easier to
this it will be more easier to understand you will understand in a very
understand you will understand in a very better way okay we will do the practical
better way okay we will do the practical implementation also
implementation also so let's see the syntax these are the
so let's see the syntax these are the two slashes that are always present in
two slashes that are always present in the x path we will write the tag name
the x path we will write the tag name slash the single slash
slash the single slash axis that is the child parent or
axis that is the child parent or ancestor or anything and there is an
ancestor or anything and there is an operator that is specially used over
operator that is specially used over here that is a scope of operator in the
here that is a scope of operator in the scope of operator these two colons and
scope of operator these two colons and then we will write the target element
then we will write the target element whatever it is the target element that
whatever it is the target element that we want to specify
we want to specify so let's have a description of this
so let's have a description of this as i said
as i said child child means it travels all the
child child means it travels all the child element of the current html tag
child element of the current html tag okay so let's look at the description of
okay so let's look at the description of it the first is a child
it the first is a child it traverses all the child elements of
it traverses all the child elements of the current html tag all the child
the current html tag all the child elements of the current html tag our
elements of the current html tag our current html tag is the self tag okay it
current html tag is the self tag okay it is traversing all the child elements of
is traversing all the child elements of the current html tag that is 9 10 11 12
the current html tag that is 9 10 11 12 and 13. next is the parent traverse all
and 13. next is the parent traverse all the parent element of the current html
the parent element of the current html tag
tag so the parent over here
so the parent over here is three okay our current html tag is
is three okay our current html tag is self so the element above the self is
self so the element above the self is the parent element right so your three
the parent element right so your three is the parent element next we have the
is the parent element next we have the following
following traverse all the elements that comes
traverse all the elements that comes after the current attack
after the current attack after the current tag right self is the
after the current tag right self is the current tag all the elements after the
current tag all the elements after the current tag that includes the seven
current tag that includes the seven eight and also the four so this is the
eight and also the four so this is the following
following okay
okay see there is a difference between
see there is a difference between following and following siblings okay
following and following siblings okay the following siblings consist of seven
the following siblings consist of seven and eight element only whereas following
and eight element only whereas following is having four seven and eight okay so
is having four seven and eight okay so there is a difference between the two
there is a difference between the two next coming to the proceeding
next coming to the proceeding traverse all the nodes that comes before
traverse all the nodes that comes before the current html tag so the current html
the current html tag so the current html tag itself before the current html tag
tag itself before the current html tag is 2 5 and 6. okay
is 2 5 and 6. okay so this is your preceding elements
so this is your preceding elements next we have the following siblings
next we have the following siblings traverse from current html tag to the
traverse from current html tag to the next sibling html tag
next sibling html tag traverse from the current html track
traverse from the current html track this self
this self to the next
to the next html tag that is this
html tag that is this this is your next html tag which is just
this is your next html tag which is just next to it right next to your self tag
next to it right next to your self tag which is seven and 8 so this will be
which is seven and 8 so this will be your following sibling
going to preceding sibling traverse from current html tag to previous sibling
current html tag to previous sibling html tag
current html tag is self previous sibling html tag is this that
previous sibling html tag is this that is the five and the six okay next we
is the five and the six okay next we have the ancestors that is your
have the ancestors that is your grandparents in parent reverse all the
grandparents in parent reverse all the ancestor elements of the current html
ancestor elements of the current html tag
tag so the ancestor over here is one this is
so the ancestor over here is one this is your current html tag itself and the
your current html tag itself and the ancestor is one next we have the
ancestor is one next we have the descendant it traverses all the
descendant it traverses all the descended elements now which consists of
descended elements now which consists of the child node the grandchild nodes of
the child node the grandchild nodes of the current html tag
the current html tag so this is the current html tag the
so this is the current html tag the child node that is the 9 10 11 12 and 13
child node that is the 9 10 11 12 and 13 and the grand child nodes that is the 14
and the grand child nodes that is the 14 15 16 17 and 18.
15 16 17 and 18. so this is all about the relationship
so this is all about the relationship table in which we covered about the
table in which we covered about the ancestor the parent the child descendant
ancestor the parent the child descendant the following the preceding the
the following the preceding the preceding sibling and the following
preceding sibling and the following siblings now let's implement this
so these two page uh these two sites we will automate today we will automate
will automate today we will automate this table as well as this form now this
this table as well as this form now this table is dynamic it keeps on changing it
table is dynamic it keeps on changing it is the
is the rediff money.rediff.com the gainers page
rediff money.rediff.com the gainers page in which we have the markets uh
in which we have the markets uh companies present over here which keeps
companies present over here which keeps on changing according to their uh prices
on changing according to their uh prices and so we're going to automate this
and so we're going to automate this table today which is dynamic also we're
table today which is dynamic also we're going to automate this form now this
going to automate this form now this form is static this is dynamic so just
form is static this is dynamic so just open your intellij id id
okay so i've already created a java class in the selenium package and i have
class in the selenium package and i have named it as selenium tutorial 7 so we're
named it as selenium tutorial 7 so we're going to implement our
going to implement our advanced xpath accesses in this uh
advanced xpath accesses in this uh selenium tutorial 7. so uh like the
selenium tutorial 7. so uh like the three lines is always the same in all
three lines is always the same in all the programs so first is the open the
the programs so first is the open the chrome browser that is the system.set
chrome browser that is the system.set property in which we have to specify the
property in which we have to specify the key value and the value that is present
key value and the value that is present that is the executable file you need to
that is the executable file you need to write over here and the key that we use
write over here and the key that we use is the
is the webdriver.chrome.driver because we're
webdriver.chrome.driver because we're launching the chrome browser the next
launching the chrome browser the next line that we write is the web driver
line that we write is the web driver driver is equal to new chrome driver and
driver is equal to new chrome driver and why do we write this i have explained in
why do we write this i have explained in the previous tutorials so you can go and
the previous tutorials so you can go and check out that
check out that the next thing that we're going to do is
the next thing that we're going to do is we are navigating to the url so we are
we are navigating to the url so we are going to use the driver.getcomma in
going to use the driver.getcomma in which we are going to navigate to the
which we are going to navigate to the particular url the next that we are
particular url the next that we are going to write is the maximizing the
going to write is the maximizing the window in which we are using the
window in which we are using the driver.manage.window.maximizecommand
okay so these are the three things that we are going to do so let's execute this
we are going to do so let's execute this and yeah we are exec we are
and yeah we are exec we are automating this table first and then we
automating this table first and then we will jump on to this page okay so first
will jump on to this page okay so first automate this one
automate this one so let's execute this first let's see we
so let's execute this first let's see we are whether we can launch the chrome
are whether we can launch the chrome browser or not
so our chrome browser is launched it's navigated
and it's maximized okay so so far our
so so far our this commands are working
this commands are working so let's get started with the xpath
so let's get started with the xpath access
access first important thing that we need to
first important thing that we need to identify is a self node on the basis of
identify is a self node on the basis of the self node we will identify the other
the self node we will identify the other relationships that is the ancestor the
relationships that is the ancestor the parent the descendants and everything
parent the descendants and everything okay
okay so first thing is we will identify the
so first thing is we will identify the self node so
self node so i take any of the
i take any of the column let me take this one okay so i'll
column let me take this one okay so i'll just click on inspect
and i'll be using the selectors hub xpath tool i have explained about the
xpath tool i have explained about the selectors hub in the previous tutorial
selectors hub in the previous tutorial how to install it so you can check out
how to install it so you can check out that i'll also give the link in the
that i'll also give the link in the description box to install it okay
description box to install it okay so uh this is the element that i
so uh this is the element that i inspected here you can see a rash
inspected here you can see a rash television network
television network so uh what i'll do is i will copy this