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 • Zoom, pan, and navigate
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
so uh what i'll do is i will copy this relative path
relative path i'll paste it over here
i'll paste it over here and
and i'll write the contains method over here
i'll write the contains method over here let me use the contains method
let me use the contains method so you can see we have one element
so you can see we have one element matching so what i'll do first i'll
matching so what i'll do first i'll identify the self so the syntax for it
identify the self so the syntax for it is that i'm writing the tag name i'm
is that i'm writing the tag name i'm using the function that is the contains
using the function that is the contains function of the x path
function of the x path i'll place a slash over here
i'll place a slash over here then i write self
then i write self and the tag name here you can see the
and the tag name here you can see the tag name is a right so i will write a
tag name is a right so i will write a and click on enter and here you can see
and click on enter and here you can see there's one element matching that is
there's one element matching that is this one
this one okay so i'll copy this
and i'll write driver
i'll write driver dot find element
dot find element by dot
by dot x path
x path and i'll place it over here and what i
and i'll place it over here and what i want to do is i want to uh click this
want to do is i want to uh click this link so let's see
link so let's see so let me run this
so our chrome browser is executed it's navigated
executed it's navigated and it's maximized
and here you can see the rash television network is
network is clicked okay so we were performing the
clicked okay so we were performing the operation of click so it's clicked
operation of click so it's clicked so i'll just close this
so i'll just close this so here you can see this is the self
so here you can see this is the self note we are using the self command we
note we are using the self command we are identifying the self command over
are identifying the self command over here just by writing one slash sells two
here just by writing one slash sells two colons and the tag name that is we're
colons and the tag name that is we're using is a
using is a okay
okay next let's see is the
next let's see is the parent node okay let's find the parent
parent node okay let's find the parent node this is our element
node this is our element now we have to find the parent node that
now we have to find the parent node that is the node about the self node that is
is the node about the self node that is the current html tag that we're taking
the current html tag that we're taking is the a right above it we have the td
is the a right above it we have the td tag okay so this will be our parent node
tag okay so this will be our parent node so now what if we don't know what i'll
so now what if we don't know what i'll do is i'll just write uh this is this
do is i'll just write uh this is this will be the command that is i'm writing
will be the command that is i'm writing the tag name a i'm using the contains
the tag name a i'm using the contains function and then i'll write one slash
function and then i'll write one slash and i'll use the parent
and i'll use the parent over here and what i'll do is i'll write
over here and what i'll do is i'll write the asterisks
the asterisks and here i can see i have one parent
and here i can see i have one parent over here which is identified for this
over here which is identified for this element that is the rash television
element that is the rash television diagram okay for this element the parent
diagram okay for this element the parent is here this is the parent where you can
is here this is the parent where you can see it's identified over here
see it's identified over here here you can see it's highlighted
here you can see it's highlighted so this is the parent this is in case
so this is the parent this is in case when we don't know the parent of the
when we don't know the parent of the current html tag okay now here we know
current html tag okay now here we know the parent right so uh since i have
the parent right so uh since i have written one slash parent and the two
written one slash parent and the two colons over here which is in scope of
colons over here which is in scope of operator and then i'll write td
operator and then i'll write td okay
okay so here you can see again it's a one
so here you can see again it's a one element matching that is this one so
element matching that is this one so what i'll do is i'll
what i'll do is i'll copy this
copy this and
and driver dot
driver dot find element
find element by dot
by dot x path
x path this
this and uh let's do one thing i will uh
and uh let's do one thing i will uh retrieve the text over here okay so
retrieve the text over here okay so let's retry the text so i'll write
let's retry the text so i'll write get text method
get text method and um
and um let me give a string
let me give a string variable over here i'll write
variable over here i'll write parent node
parent node then the next thing that i'll write is
then the next thing that i'll write is the system out.println
the system out.println i'll type
similarly i'll do for this one also let's see what value do we get
let's see what value do we get get text
get text and
the self node is
node is so let's see what value it prints
so let's see what value it prints so i will execute this command
so i will execute this command a chrome browser is launched
a chrome browser is launched it's navigated
it's navigated it's maximized
it's maximized so let's see see the self note is large
so let's see see the self note is large television network and the parent node
television network and the parent node is rash television network now here
is rash television network now here there's one thing to notice that is
there's one thing to notice that is there any value in td
there any value in td here we can see it's here is there any
here we can see it's here is there any value in td there is no value entity
value in td there is no value entity there is there is no value entity so
there is there is no value entity so that is the reason why
that is the reason why we are not fine we are not getting any
we are not fine we are not getting any value printed over here the only value
value printed over here the only value that we are getting over here is uh is
that we are getting over here is uh is rash television network because under
rash television network because under the parent element under the td tag we
the parent element under the td tag we have the a tag right which has the link
have the a tag right which has the link of the rash television network so that
of the rash television network so that is the reason why it is printing rush
is the reason why it is printing rush television network if td would be having
television network if td would be having any value the parent or value would be
any value the parent or value would be different from the self node value okay
different from the self node value okay we will understand that in the forms
we will understand that in the forms when we will do uh we will navigate the
when we will do uh we will navigate the different website this form website at
different website this form website at that time we will see the values also at
that time we will see the values also at that time the values will be different
that time the values will be different okay so for now to understand the td tag
okay so for now to understand the td tag is having no value so that is the reason
is having no value so that is the reason why we're getting the raw television
why we're getting the raw television network away
network away okay
okay so now moving to the next thing is see
so now moving to the next thing is see the
the child nodes
child nodes so now uh if i write
child to collins and the asterisk
to collins and the asterisk so here we can see we have zero element
so here we can see we have zero element matching over here there is no
matching over here there is no child node of this a tag okay
child node of this a tag okay so now what we're going to do is
so now what we're going to do is first uh we will go to the ancestor
first uh we will go to the ancestor and then we will find the child elements
and then we will find the child elements for ancestor that is a tr tag is having
for ancestor that is a tr tag is having different child elements like here you
different child elements like here you can see the b 34.05
can see the b 34.05 and 39.20 so these are the child
and 39.20 so these are the child elements of tr tag right so we're going
elements of tr tag right so we're going to find the tr tag the uh tier tags
to find the tr tag the uh tier tags child elements okay so how we're going
child elements okay so how we're going to do this is the self tag that is the a
to do this is the self tag that is the a type the parent tag is a td tag and the
type the parent tag is a td tag and the ancestor tag that we can see over here
ancestor tag that we can see over here is the tr tag okay so first we'll go to
is the tr tag okay so first we'll go to the tr tag
the tr tag we'll go to the ancestor and then from
we'll go to the ancestor and then from there we will traverse the child
there we will traverse the child elements okay so how we gonna do that
elements okay so how we gonna do that just have a look at it
just have a look at it this is the tag name that i'm using that
this is the tag name that i'm using that is the a tag name and the contains
is the a tag name and the contains method that is given over here then i'm
method that is given over here then i'm given the slash over here
given the slash over here and then i'll write
and then i'll write the ancestor
the ancestor here it is okay
here it is okay who's my ancestor my ancestors tag is tr
who's my ancestor my ancestors tag is tr tag here you can see this is the tr tag
tag here you can see this is the tr tag click on enter and here i can see
click on enter and here i can see there's one element matching to it
there's one element matching to it okay
okay this is the element that is matching to
this is the element that is matching to it here you can see it's getting
it here you can see it's getting highlighted
highlighted okay so i have gone to my ancestor after
okay so i have gone to my ancestor after i was to tell my ancestor now i want to
i was to tell my ancestor now i want to find the child elements of my ancestor
find the child elements of my ancestor so what i'm going to do is i'm going to
so what i'm going to do is i'm going to put another slash over here
put another slash over here write
write child
child colons and let's see how many i'm
colons and let's see how many i'm getting five child elements over here
getting five child elements over here this is the first one
this is the first one this is the second one this is the third
this is the second one this is the third one this is the fourth one and this is
one this is the fourth one and this is the fifth one
the fifth one okay now see selectors hub is having
okay now see selectors hub is having this feature of identifying these five
this feature of identifying these five elements which are matching which is
elements which are matching which is showing over here also so it's a great
showing over here also so it's a great tool to use so i would suggest you to
tool to use so i would suggest you to use selectors hub for the
use selectors hub for the access when you're finding the xpath
access when you're finding the xpath access because you will get a knowledge
access because you will get a knowledge of uh writing the expert as well it's
of uh writing the expert as well it's not that that you're getting used to
not that that you're getting used to this tool or not see sometimes people
this tool or not see sometimes people think by using this tool we are not
think by using this tool we are not getting a hang of writing your x bar
getting a hang of writing your x bar that's not the point if you write your
that's not the point if you write your expert over here it tells you whether
expert over here it tells you whether you're writing it right or wrong like if
you're writing it right or wrong like if i
i delete if i just clear this one so you
delete if i just clear this one so you can see it's red in color but when i
can see it's red in color but when i write this it's it's it's not having any
write this it's it's it's not having any color so it shows you that the
color so it shows you that the expert that you're writing is correct or
expert that you're writing is correct or wrong so that will help you like if you
wrong so that will help you like if you write bigger scripts so in that case
write bigger scripts so in that case that will help you so it's a very great
that will help you so it's a very great it is a very good tool to use so use
it is a very good tool to use so use selectors hub i would prefer you to use
selectors hub i would prefer you to use selectors hub okay
selectors hub okay as in the previous tutorial i explained
as in the previous tutorial i explained about the crowbar plugin also but the
about the crowbar plugin also but the selectors hub is the advanced version of
selectors hub is the advanced version of the crow path plugin so i would
the crow path plugin so i would recommend not to use crow path for now
recommend not to use crow path for now because uh it's so absolute it's not
because uh it's so absolute it's not that updated till now so selectors hub
that updated till now so selectors hub is more updated so use selectors up
is more updated so use selectors up okay like here you can see i placed the
okay like here you can see i placed the asterisk mark and here you can see uh
asterisk mark and here you can see uh there are different uh td tags present
there are different uh td tags present over here that is the child elements one
over here that is the child elements one two three four five we are having five
two three four five we are having five elements over here okay so now what
elements over here okay so now what we're going to so till now what we did
we're going to so till now what we did we went to the ancestor tag that is a tr
we went to the ancestor tag that is a tr tag and then we traverse the child
tag and then we traverse the child elements over here what i'll do is i
elements over here what i'll do is i will write driver
dot x dot
dot find elements because i'm finding
find elements because i'm finding multiple elements over here okay the
multiple elements over here okay the child nodes that i'm having the number
child nodes that i'm having the number of child node is five i'm not finding
of child node is five i'm not finding one element i'm finding multiple
one element i'm finding multiple elements over here okay so find elements
elements over here okay so find elements then i'll write by dot
then i'll write by dot x path
x path and i will write the entire x path over
and i will write the entire x path over here
now what what i'll do is i want to uh i want to know the number of child
i want to know the number of child elements present over here i'll print
elements present over here i'll print the child number of child elements
the child number of child elements present over here so i'll write
present over here so i'll write child node
child node is equal to
is equal to this now what we are finding we are
this now what we are finding we are finding a web element a multiple fweb
finding a web element a multiple fweb elements we are finding right
elements we are finding right so i'll write
web element now this is a web element child or not a
now this is a web element child or not a child node but we are finding multiple
child node but we are finding multiple elements we are using find elements
elements we are using find elements right so it is a list of multiple
right so it is a list of multiple elements so what i'll do is i'll write
elements so what i'll do is i'll write list
web element child node driver dot find elements y dot x bar and the x bar that
elements y dot x bar and the x bar that is present over here now what i want is
i want to print this so
so so the number of child nodes are
so the number of child nodes are child
child node dot
node dot size okay so let's and after this uh
size okay so let's and after this uh what i want is i want to close the
what i want is i want to close the browser
browser so i'll write driver dot
so i'll write driver dot close
so the chrome browser is launched it's navigated
and it's maximized and it's closed okay now here it's you here you can see the
now here it's you here you can see the self note is rash television network the
self note is rash television network the parent node is rash television network
parent node is rash television network the same value is given because the td
the same value is given because the td tag is not having any value and the
tag is not having any value and the number of child nodes are five here you
number of child nodes are five here you can see we have five elements that is
can see we have five elements that is identified so the number of child nodes
identified so the number of child nodes are five
are five okay so so far we have seen the self
okay so so far we have seen the self known the parent node in the child node
known the parent node in the child node let's uh see the ancestor node since we
let's uh see the ancestor node since we have seen already but let's print it
have seen already but let's print it okay
okay so what i'll do is
so what i'll do is same
these are my ancestors so let me see so there is only one ancestor over here
there is only one ancestor over here okay so i will copy this
okay so i will copy this and i'll write
and i'll write driver
driver dot
dot find element
by dot x path
x path the ancestor
the ancestor and what i want is i want get text
and what i want is i want get text so i'll save it in a variable
so i'll save it in a variable that is string variable i'll write it at
that is string variable i'll write it at ancestor
ancestor node
node is equal to driver dot fine element by
is equal to driver dot fine element by dot expat
dot expat and
and next i'll print it
ancestor [Music]
[Music] node is
node is and plus
and plus ancestor node okay
ancestor node okay so let's see
so let's see let's run this command
so i chrome browser is launched it's navigated
launched it's navigated and
and it's maximized and it's closed so here
it's maximized and it's closed so here you can see the ancestor node is
you can see the ancestor node is television network b now see
television network b now see when you're traversing the ancestor that
when you're traversing the ancestor that is the tr tag under tr tag we have the
is the tr tag under tr tag we have the different uh
different uh tags right that is the td tag the td
tags right that is the td tag the td this tag then this td tag then the tr
this tag then this td tag then the tr tag is closing
tag is closing now from this tag
now from this tag to this tag
to this tag the number of tags that we are having it
the number of tags that we are having it will print all the tags first is
will print all the tags first is printing the raj
printing the raj here you can see the last television
here you can see the last television then it's printing b then it's printing
then it's printing b then it's printing 34.05
34.05 just have a look at it
here you can see we have the rash television network the rash television
television network the rash television network then we are printing b
network then we are printing b then we are printing 34.05 34.05 and
then we are printing 34.05 34.05 and then the 39.02
then the 39.02 and then
and then plus 15.12
plus 15.12 so it's printing the entire eye because
so it's printing the entire eye because under the tr tag under this tr tag there
under the tr tag under this tr tag there are different td tags that is present
are different td tags that is present and under td tag we have the different
and under td tag we have the different values that are present over here that
values that are present over here that is the uh rash television network then
is the uh rash television network then the b then thirty four point zero four
the b then thirty four point zero four thirty nine point zero two and so on
thirty nine point zero two and so on okay so like these there are uh five to
okay so like these there are uh five to six elements that we have printed
six elements that we have printed printed over here this is all about the
printed over here this is all about the ancestor
ancestor now let's see
now let's see the
the following
following so i have the two slashes that is always
so i have the two slashes that is always there for the x path the a tag the tag
there for the x path the a tag the tag name that i'm using is a contains the
name that i'm using is a contains the rash television network this is the
rash television network this is the element that is the self element now
element that is the self element now from here i want to see the following
from here i want to see the following elements okay so what i'll do is put one
elements okay so what i'll do is put one slash i'll write following
two columns now i don't know what are my following elements so i'll just put
following elements so i'll just put the asterisks mark and here you can see
the asterisks mark and here you can see we can see there are almost 13 000
we can see there are almost 13 000 elements that is matching to the
elements that is matching to the following element you can see
following element you can see so just have a look over here the one
so just have a look over here the one that is highlighted the blue one is the
that is highlighted the blue one is the following elements that is over there
following elements that is over there this these are the following elements
this these are the following elements okay
okay the this blue one that is highlighted
the this blue one that is highlighted over here there are almost 13 000
over here there are almost 13 000 elements that is matching over here so
elements that is matching over here so this is the following element
this is the following element so i'll just print the number of
so i'll just print the number of following elements that is present over
following elements that is present over here
here so i'll just write
so i'll just write driver
driver dot
dot find elements
find elements by dot
by dot x path
x path i put the following
i put the following and
let's give a web element
give a web element the
the i'll write the
i'll write the is equal to driver dot and it is of type
is equal to driver dot and it is of type list
list because the number of uh web elements
because the number of uh web elements that is identified over here are
that is identified over here are almost 13 000 web elements will be
almost 13 000 web elements will be identified over here so i'm writing list
identified over here so i'm writing list web element
web element and the following tag that is the web
and the following tag that is the web element that i'm specifying over here in
element that i'm specifying over here in the driver.find elements by.xpath
the driver.find elements by.xpath and next what i want is
and next what i want is so i want
so i want the number of
following elements
elements from the
from the current
current html
html tag is
tag is and i will write
and i will write following tag
following tag size let's execute this
okay so my chrome browser is launched it's navigated
it's navigated and it's uh
and it's uh maximized
maximized so these are the number of the following
so these are the number of the following elements from the current customer tag
elements from the current customer tag that is present over here now let's see
that is present over here now let's see the following sibling
the following sibling okay so let's check out the following
okay so let's check out the following siblings that are present over here so
siblings that are present over here so what i'll do is i will
what i'll do is i will just write the following
just write the following sibling
sibling i don't know the number of following
i don't know the number of following siblings so i'll just write the
siblings so i'll just write the asterisks
asterisks and it says that there are zero number
and it says that there are zero number of following siblings present over here
of following siblings present over here that is there is no node next to the
that is there is no node next to the self node so again what we'll do
self node so again what we'll do we will traverse to the ancestor
we will traverse to the ancestor so our ancestor tag is the tr tag
so our ancestor tag is the tr tag slash
slash following
and then let's see so what we did we traverse to the ancestor tag that is the
traverse to the ancestor tag that is the tr tag and from tr tag we traverse the
tr tag and from tr tag we traverse the following siblings
following siblings so the following siblings that are
so the following siblings that are present over here
present over here are these these are the following
are these these are the following siblings you know this uh blue marking
siblings you know this uh blue marking done over here these are the following
done over here these are the following siblings okay so what i'll do i'll just
siblings okay so what i'll do i'll just print the number of the following
print the number of the following siblings over here so what i'll write is
siblings over here so what i'll write is i will write
i will write driver dot
driver dot find elements
find elements by dot x path
by dot x path and the
and the following sibling over here
following sibling over here and then i will
and then i will following siblings okay
following siblings okay so let's execute this
so my chrome browser is launched it's navigated it's maximized
okay so here it is the following siblings are
siblings are uh
uh 1705 okay so the number of following
1705 okay so the number of following siblings that are present over here is
siblings that are present over here is 1700.
1700. so now let's see the proceeding
so now let's see the proceeding okay so what i'll do is i will
okay so what i'll do is i will slash proceeding now i don't know the
slash proceeding now i don't know the number of preceding elements over here
number of preceding elements over here so i'll just write asterisk and here you
so i'll just write asterisk and here you can see
can see this is the entire preceding element
this is the entire preceding element that is present over here
that is present over here the entire preceding elements that we
the entire preceding elements that we have is this okay
have is this okay now what if i write
now what if i write preceding
preceding sibling
sibling so there are zero elements that is
so there are zero elements that is matching over here so
matching over here so so again we will go to the ancestor
so again we will go to the ancestor the tr tag
the tr tag and then we will go to the preceding
and then we will go to the preceding sibling
sibling so there are six elements that is
so there are six elements that is matching to the preceding sibling
matching to the preceding sibling that is uh these elements
that is uh these elements before the rash television network the
before the rash television network the element that is present is the preceding
element that is present is the preceding siblings after the rash television
siblings after the rash television network the elements that are present is
network the elements that are present is the following siblings
the following siblings and the elements that are present before
and the elements that are present before the last television network all these
the last television network all these elements this entire pace that is
elements this entire pace that is present before the rash television
present before the rash television network is your proceeding again let me
network is your proceeding again let me show you
show you this is your preceding sibling
this is your preceding sibling but whereas your proceeding is
but whereas your proceeding is this
this this is your proceeding and you proceed
this is your proceeding and you proceed preceding siblings for only these
preceding siblings for only these columns that is present over here before
columns that is present over here before the rash television network so that is
the rash television network so that is the difference between the preceding and
the difference between the preceding and the preceding siblings okay so keep in
the preceding siblings okay so keep in mind that so let's first do the
mind that so let's first do the preceding one so i'll just copy this
preceding one so i'll just copy this and we will see that at least 200
and we will see that at least 200 elements that is present over here so
elements that is present over here so i'll just write
i'll just write list
list we will we are finding the web element
we will we are finding the web element over here and i'll write the
preceding so pre and then driver dot find elements
find elements by dot
by dot x path
x path and then this syntax of x path
and then this syntax of x path and
and the next line i'll write s out
the next line i'll write s out i'll write
i'll write the number of
preceding nodes are
so our chrome browser is launched it's navigated
navigated and it's maximized
and it's maximized okay and here you can see the following
okay and here you can see the following siblings are 1700 and the number of
siblings are 1700 and the number of preceding nodes that are there it's 200
preceding nodes that are there it's 200 okay so 217 so these are some preceding
okay so 217 so these are some preceding now let's see the preceding siblings
now let's see the preceding siblings okay so what i'll do is i will first
okay so what i'll do is i will first find the number of elements that is
find the number of elements that is present so what i'll do as a first
present so what i'll do as a first traverse to the ancestor first ever so
traverse to the ancestor first ever so the ancestor we have the answer tag that
the ancestor we have the answer tag that is a tr tag then i'll write one slash
is a tr tag then i'll write one slash and then i will write uh
and then i will write uh preceding siblings
this and i'll write the asterisk sign and you can see we have six elements
and you can see we have six elements matching over here so i'll just copy
matching over here so i'll just copy this x path
this x path and
and i'll write list
is equal to driver dot fine elements by dot x path
by dot x path and i'll place the x path over here
and i'll place the x path over here so s out
so s out and
and the number of
the number of okay so
okay so let's run this now
it's navigated it's maximized
okay so here it shows the number of preceding siblings are six
preceding siblings are six similarly we have seen over here there
similarly we have seen over here there are six elements that are matching so
are six elements that are matching so the number of preceding elements uh
the number of preceding elements uh preceding siblings are six
preceding siblings are six so um
so um [Music]
[Music] this is the code that we have executed
this is the code that we have executed today for the expert access in which we
today for the expert access in which we have seen the self node first and the
have seen the self node first and the parent node the child node the ancestor
parent node the child node the ancestor node the following the following
node the following the following siblings the proceeding and the
siblings the proceeding and the preceding siblings okay so for so far we
preceding siblings okay so for so far we have understood how do we write these
have understood how do we write these elements when we're having a dynamic uh
elements when we're having a dynamic uh web page
web page so this table is dynamic it keeps on
so this table is dynamic it keeps on changing you can check it out also if
changing you can check it out also if you like open today and open it tomorrow
you like open today and open it tomorrow so these companies keep on switching
so these companies keep on switching okay depending on their change in prices
okay depending on their change in prices this is a way that we can identify the
this is a way that we can identify the ancestors and child nodes how to first
ancestors and child nodes how to first traverse to the child node and then for
traverse to the child node and then for how to first traverse to the ancestor
how to first traverse to the ancestor node and then to the child node so this
node and then to the child node so this is this is the way to do it so now this
is this is the way to do it so now this is the first web page that we traverse
is the first web page that we traverse and then the next webpage that we're
and then the next webpage that we're going to automate is this one okay uh
going to automate is this one okay uh this code is available on the github so
this code is available on the github so i'll uh give the link in the description
i'll uh give the link in the description box so you can check out okay so uh this
box so you can check out okay so uh this is the second uh
is the second uh web page that we are going to automate
web page that we are going to automate we're going to use the xpath axis over
we're going to use the xpath axis over here we will find the parent the self
here we will find the parent the self element and all the elements the xpath
element and all the elements the xpath access elements over here
access elements over here so first is to identify the self element
so first is to identify the self element right the self node so i'll be taking
right the self node so i'll be taking this company name as the self node so
this company name as the self node so here it is
here it is the company name
the company name okay so now what i'm going to do is
okay so now what i'm going to do is i'm going to open my selectors hub
i'm going to open my selectors hub and let me see yes this company name is
and let me see yes this company name is myself note
myself note and here it is
and here it is this is the
this is the just copy the relative path over here
just copy the relative path over here i'm using the two slashes first the two
i'm using the two slashes first the two slashes that is used for the x part
slashes that is used for the x part normally then the input tag here you can
normally then the input tag here you can see we have the input tag and the id uh
see we have the input tag and the id uh locator has been used the id locator in
locator has been used the id locator in which the value is the company
which the value is the company okay
okay so as i said uh the expert access can be
so as i said uh the expert access can be used with any of the locators and in
used with any of the locators and in fact it can be used with the uh methods
fact it can be used with the uh methods also
also okay so now what i'm going to do is i'm
okay so now what i'm going to do is i'm just going to write
just going to write a slash
a slash this is the self element so i'll write
this is the self element so i'll write the cells
the cells two colons and the in the tag that is
two colons and the in the tag that is the input tag right the tag that is
the input tag right the tag that is usable over here is the input type so
usable over here is the input type so you can see that there is only one
you can see that there is only one element matching that is this element
element matching that is this element okay so i'll just copy this
so i'll write driver dot
dot find element because one element i'm
find element because one element i'm finding by dot
finding by dot x path and i will specify the x path
x path and i will specify the x path over here and the command that i want to
over here and the command that i want to send over here is send keys the company
send over here is send keys the company name is
name is abc
abc that's the company name
that's the company name run this
run this so my chrome browser is launched
so my chrome browser is launched it's navigated
it's navigated it's maximized and you can see the
it's maximized and you can see the company name that the command that is
company name that the command that is sent over here is abc
sent over here is abc okay
okay so here our self node is identified
so here our self node is identified let's find the parent
let's find the parent node
node so here
so here this is a self node so uh i'm writing
this is a self node so uh i'm writing the two slashes that is the in and the
the two slashes that is the in and the tag name that i'm using is the input tag
tag name that i'm using is the input tag the id locator that i'm using and the
the id locator that i'm using and the value is company so
value is company so slash and i'll be using parent
slash and i'll be using parent now i don't know the number of parents
now i don't know the number of parents over here so i'll just write asterisks
over here so i'll just write asterisks and then let me see there is only one
and then let me see there is only one element
element the form here you can see why see
the form here you can see why see because your input above input we have
because your input above input we have the select tag which is of the same
the select tag which is of the same level then we have the div tag which is
level then we have the div tag which is of the same level
of the same level next we have the form tag which is the
next we have the form tag which is the parent tag why because above input now
parent tag why because above input now you must be saying about the self tag
you must be saying about the self tag that i said the current html node is the
that i said the current html node is the this this input tag above this input tag
this this input tag above this input tag we have the select tag right so this
we have the select tag right so this should be parent tag no
should be parent tag no this tag and this tag are on the same
this tag and this tag are on the same level the parent tag over here is the
level the parent tag over here is the form
form so the parent tag over here is form
so the parent tag over here is form right so we will access this element so
right so we will access this element so what i'm going to do is i'm just going
what i'm going to do is i'm just going to
to copy this i'll just write driver dot
copy this i'll just write driver dot find element
find element now uh sometimes uh there is a question
now uh sometimes uh there is a question where people ask that the for relative x
where people ask that the for relative x path for absolute x bar are the
path for absolute x bar are the different different ways of writing like
different different ways of writing like by relative x path by absolute x but by
by relative x path by absolute x but by x path axis is no
x path axis is no there is only one x path that is by dot
there is only one x path that is by dot x path okay okay so this is what and
x path okay okay so this is what and what i want is i want to find the value
what i want is i want to find the value let me find the value of it what value
let me find the value of it what value do i get from here so i'll write string
parent is equal to drive and i'll write the
and i'll write the parent so chrome browser is launched
it's maximized and the company name that is the abc has been sent over here
now you must be saying that your only one element is found
one element is found but the value that is printed over here
but the value that is printed over here here you can see there is a number of
here you can see there is a number of values that is print the parent values
values that is print the parent values name email role
name email role job and all these cities names and
job and all these cities names and states names and
states names and this entire thing is printed why there's
this entire thing is printed why there's only one element matching and how come
only one element matching and how come all these values are printed why as i
all these values are printed why as i said in the previous time when we were
said in the previous time when we were automating that uh
automating that uh table that dynamic table at that time
table that dynamic table at that time also i said that when we are traversing
also i said that when we are traversing when we are traversing to a parent tag
when we are traversing to a parent tag or an ancestor tag so all the tags that
or an ancestor tag so all the tags that are under it
are under it the values are printed when we are
the values are printed when we are printing the value we are finding get
printing the value we are finding get text right the get text method has been
text right the get text method has been used over here through gettext method we
used over here through gettext method we are finding the uh
are finding the uh values that we are finding the text that
values that we are finding the text that is there for the parent
is there for the parent string see the variable that we are
string see the variable that we are using is parent over here
using is parent over here right and the element that we are
right and the element that we are finding is this the parent element right
finding is this the parent element right so we are printing the parent element
so we are printing the parent element right so print while printing the parent
right so print while printing the parent element all the elements that are under
element all the elements that are under form
form all the elements are printed over here
all the elements are printed over here okay
okay so here you can see until the form is
so here you can see until the form is ended till here
ended till here so all the elements that are present in
so all the elements that are present in here all the elements that are present
here all the elements that are present see here you can see it's highlighted
if you can see this entire frame has been done framing has been done okay
been done framing has been done okay this yellow color frame that is done
this yellow color frame that is done this is your parent tag that is this
this is your parent tag that is this showing
showing this entire thing is your parent type so
this entire thing is your parent type so everything is printed over here that
everything is printed over here that doesn't name your email your role your
doesn't name your email your role your company your country your postal code
company your country your postal code your username everything that is present
your username everything that is present over here by registering everything is
over here by registering everything is present we have printed on this
present we have printed on this uh
uh console okay so here you can see by
console okay so here you can see by registering you confirm similarly over
registering you confirm similarly over here also by registering your confirm so
here also by registering your confirm so everything that is present under this
everything that is present under this form tag is printed over here in the
form tag is printed over here in the parent
parent this is one way so i'll just
this is one way so i'll just comment this because it's printing a
comment this because it's printing a long
long message so this is the way we can do the
message so this is the way we can do the parent app
parent app next we have the
next we have the child
child notes i'll write slash
notes i'll write slash child
child to colons
to colons and the asterisk mark and you can see
and the asterisk mark and you can see zero child elements that is identified
zero child elements that is identified over here
over here so what you're going to do again
so what you're going to do again we go to parent
we go to parent we can go to parent the parent tag that
we can go to parent the parent tag that we're using is the form
we're using is the form slash
slash child
child to colons and then we can use the
to colons and then we can use the asterisk and you can see we have 26
asterisk and you can see we have 26 elements that are highlighted here you
elements that are highlighted here you can see 26 elements the entire form is
can see 26 elements the entire form is highlighted over here
highlighted over here if you can see each and everything we
if you can see each and everything we have the name we have the email we have
have the name we have the email we have the role company the country the postal
the role company the country the postal code the user name and all these
code the user name and all these elements are highlighted over here okay
elements are highlighted over here okay so what i'm going to do is i'll just
so what i'm going to do is i'll just print the number of elements that is
print the number of elements that is matching over yours similarly we did in
matching over yours similarly we did in the previous so while navigating the
the previous so while navigating the previous
previous web table
web table the table that was there the dynamic
the table that was there the dynamic table so i'll just write
table so i'll just write list
list and the web element
and the web element driver dot find elements i'm using find
driver dot find elements i'm using find elements
elements by dot x path and i will specify the x
by dot x path and i will specify the x path over here
path over here and
and [Music]
[Music] what i want is i want to find the number
what i want is i want to find the number of uh
of uh child nodes right
child nodes right plus
plus sign notes dot
sign notes dot size
size we're using the size method see the
we're using the size method see the reason why i'm automating two webpages
reason why i'm automating two webpages because that was a dynamic one this is a
because that was a dynamic one this is a static one there is no such changes in
static one there is no such changes in it but you should know you should have a
it but you should know you should have a hang of it and it's a good practice to
hang of it and it's a good practice to practice this
practice this way okay so you can automate any of the
way okay so you can automate any of the site like you can automate the
site like you can automate the facebook.com you can automate gmail you
facebook.com you can automate gmail you can automate the google so you can
can automate the google so you can automate any one of it that's on you so
automate any one of it that's on you so let's run this command okay so our
let's run this command okay so our chrome browser is launched
chrome browser is launched it's navigated
it's maximized and the company name that is the abc company name
is the abc company name and let's see the number of child nodes
and let's see the number of child nodes are 25 so this way we have found the
are 25 so this way we have found the number of child nodes
number of child nodes now let's find following
now let's find following nodes
nodes so this is our self
so this is our self after the self node all the boxes that
after the self node all the boxes that are showing over here is your following
are showing over here is your following right till the
right till the end so i'll just write
end so i'll just write following
following and we have the 562 elements that is the
and we have the 562 elements that is the country postal username this entire
country postal username this entire thing that is there right
thing that is there right all the thing that is present over here
all the thing that is present over here this uh country postal code username by
this uh country postal code username by registering all these elements that is
registering all these elements that is the 562 elements that is present over
the 562 elements that is present over here are under your following
here are under your following okay
okay similar same thing we'll do
similar same thing we'll do we will copy it
we will copy it we will write list
we will write list web element
web element so let's execute this
chrome browser is launched it's navigated
it's navigated and it's maximized
and it's maximized and here our country value is being sent
and here our country value is being sent that is in abc
that is in abc and the number of following nodes are
and the number of following nodes are 560. so there were among 500
560. so there were among 500 nodes that were present so the number of
nodes that were present so the number of following nodes that are present over
following nodes that are present over here
here similarly we'll go for preceding
similarly we'll go for preceding okay so this is the proceeding that we
okay so this is the proceeding that we have so let me just print the values of
have so let me just print the values of here see it's similar to the previous uh
here see it's similar to the previous uh web piece that we automated so this is
web piece that we automated so this is the same
the same this is just for the practice purpose
this is just for the practice purpose so
so open your chrome browser it's launched
open your chrome browser it's launched it's navigated it's maximized and the
it's navigated it's maximized and the company name is also been sent over here
company name is also been sent over here and here you can see we have the number
and here you can see we have the number of child nodes that are given is 25 the
of child nodes that are given is 25 the number of following nodes is 560 and the
number of following nodes is 560 and the number of proceedings that is given away
number of proceedings that is given away is 108. okay now let's find the
is 108. okay now let's find the following siblings
following siblings okay
okay so this is the command that i've written
so this is the command that i've written i have written the two slashes the input
i have written the two slashes the input the tag name the id locator that i'm
the tag name the id locator that i'm using and the values company and slash
using and the values company and slash following siblings and two colons and
following siblings and two colons and the asterisk mark so this shows the
the asterisk mark so this shows the following sibling that is the country
following sibling that is the country person code username and this value and
person code username and this value and the sign up following siblings means
the sign up following siblings means this is the form right this is the
this is the form right this is the parent tag over here is the form
parent tag over here is the form parent tag right so under the parent tag
parent tag right so under the parent tag after the company name all the values
after the company name all the values that is coming all the web elements that
that is coming all the web elements that is identified after the company name are
is identified after the company name are your following siblings whereas
your following siblings whereas following means the country the postal
following means the country the postal the username this the sign up and then
the username this the sign up and then this login i already have a sale force
this login i already have a sale force developer environment all this is the
developer environment all this is the following and whereas the following
following and whereas the following siblings is the country postal code
siblings is the country postal code username and this value in the signup
username and this value in the signup value similarly for preceding
value similarly for preceding let me show you the proceeding as well
let me show you the proceeding as well so this is the proceeding there are 12
so this is the proceeding there are 12 elements that is the elements before the
elements that is the elements before the company that is the company role email
company that is the company role email name and whereas when we are finding the
name and whereas when we are finding the preceding element
preceding element not the preceding sibling the preceding
not the preceding sibling the preceding element we have all this also that is
element we have all this also that is get your own developer addition and all
get your own developer addition and all all this is also included okay so
all this is also included okay so proceeding here you can see in the
proceeding here you can see in the output that we have found that there are
output that we have found that there are proceedings only 108 whereas the
proceedings only 108 whereas the preceding siblings is 12 elements so
preceding siblings is 12 elements so there is a difference between the two
there is a difference between the two okay so remember that
okay so remember that so this is the two syntax that i've
so this is the two syntax that i've written the two commas the following
written the two commas the following siblings and the preceding sibling so
siblings and the preceding sibling so let's execute it
let's execute it this is our chrome browser's launch
this is our chrome browser's launch it's navigated it's maximized and the
it's navigated it's maximized and the company name abc has been sent over here
company name abc has been sent over here and here you can see the number of
and here you can see the number of following siblings at 12 the number of
following siblings at 12 the number of preceding siblings at one
preceding siblings at one okay
okay so uh this way we have seen the child
so uh this way we have seen the child node the parent node the following node
node the parent node the following node preceding nodes and all the nodes that
preceding nodes and all the nodes that we have study the relationship of nodes
we have study the relationship of nodes as well so to know we have covered many
as well so to know we have covered many uh things about the x path we have
uh things about the x path we have covered what is the x path the different
covered what is the x path the different types of the x bar that is the absolute
types of the x bar that is the absolute and the relative and which one is better
and the relative and which one is better to use
to use then we have studied about the expert
then we have studied about the expert operators like the and the or operator
operators like the and the or operator the contains method the text method and
the contains method the text method and the start swift method also we have
the start swift method also we have studied about the xpath accesses so this
studied about the xpath accesses so this is a simple cheat sheet which i usually
is a simple cheat sheet which i usually uh use to refer the xpath whenever i
uh use to refer the xpath whenever i study xpath or need to revise xpath so
study xpath or need to revise xpath so this is a cheat sheet which i usually um
this is a cheat sheet which i usually um use it you can also use it while going
use it you can also use it while going before the interviews so let's get a
before the interviews so let's get a hang of it so these are some of the uh
hang of it so these are some of the uh methods that is used for the xpath axis
methods that is used for the xpath axis like i said the two colons in the scope
like i said the two colons in the scope of and we're using the uh two slashes or
of and we're using the uh two slashes or one slashes now there's one thing that i
one slashes now there's one thing that i need to remind you see over here you can
need to remind you see over here you can see in the axises which is the cell
see in the axises which is the cell following following sibling we have a
following following sibling we have a two slashes specified over here
two slashes specified over here it does not matter where you whether you
it does not matter where you whether you put the two slashes or the one slash for
put the two slashes or the one slash for example let me show you
example let me show you uh this was the page that we were
uh this was the page that we were navigating like suppose uh we were
navigating like suppose uh we were inspecting this page this one and
inspecting this page this one and we were traversing to the parent right
we were traversing to the parent right and there's only one parent element so
and there's only one parent element so this one so i have used
this one so i have used two uh slashes over here if you can see
two uh slashes over here if you can see let me i'll write it in front of you
let me i'll write it in front of you wait
two slashes i have used there are two slashes over here and i'm using parent
slashes over here and i'm using parent two colors that is in scope of operator
two colors that is in scope of operator and
and a asterisk sign which is used to select
a asterisk sign which is used to select all the elements right it shows all the
all the elements right it shows all the elements so it's using it's selecting
elements so it's using it's selecting only one element is matching over here
only one element is matching over here that is the form tag as i said the form
that is the form tag as i said the form tag is the parent type whereas if i use
tag is the parent type whereas if i use one slash i have used only one slash and
one slash i have used only one slash and parent
and two colons and asterisk still the one element still only one
still the one element still only one element is
element is matching okay so it does not matter if
matching okay so it does not matter if you uh
you uh put two slashes or one slash to it okay
put two slashes or one slash to it okay so next we have the slash tag name the
so next we have the slash tag name the tag name slash tag name is used to write
tag name slash tag name is used to write the except x bar that we usually write
the except x bar that we usually write that is a relative x path the syntax of
that is a relative x path the syntax of it is this the two slashes the tag name
it is this the two slashes the tag name at the rate the attribute is equal to
at the rate the attribute is equal to value for example id and the value that
value for example id and the value that we use it in country or anything then we
we use it in country or anything then we have the contains method in the text
have the contains method in the text method in the contents method we can
method in the contents method we can have the two slashes tag name and the
have the two slashes tag name and the contains method
contains method and we can write at the rate attribute
and we can write at the rate attribute and the value for example at the rate id
and the value for example at the rate id and the value that is country
and the value that is country similarly if you want to use contains
similarly if you want to use contains method and the text method together okay
method and the text method together okay so what we're going to do is tag name
so what we're going to do is tag name contains
contains text and then the value now here the
text and then the value now here the star the asterisk which is used over
star the asterisk which is used over here right it selects all the methods
here right it selects all the methods with the same value now for example if i
with the same value now for example if i write two slashes and the asterisk
write two slashes and the asterisk method contains text and the value that
method contains text and the value that i'm writing is country so what will do
i'm writing is country so what will do what it will do is it will uh select all
what it will do is it will uh select all the value which is having country okay
the value which is having country okay whereas if i'm taking tag name like for
whereas if i'm taking tag name like for example if i'm writing input so under
example if i'm writing input so under input tag whatever country values are
input tag whatever country values are present it will select that okay so that
present it will select that okay so that is the difference between the asterisk
is the difference between the asterisk and the tag name that is present over
and the tag name that is present over here
here next we have the logical and in the or
next we have the logical and in the or operator that we were using similarly we
operator that we were using similarly we can just use and and the or the chart i
can just use and and the or the chart i also i have given the chart about the
also i have given the chart about the and in the or operator in which case the
and in the or operator in which case the element will be identified in which case
element will be identified in which case it will not be identified you can check
it will not be identified you can check it out in the previous tutorial
it out in the previous tutorial next we have to start with the function
next we have to start with the function that we're using
that we're using this is similar to the
this is similar to the dynamic functionality which we were
dynamic functionality which we were starting in the previous tutorial the on
starting in the previous tutorial the on and off button which i explained
and off button which i explained so you can write the starts with either
so you can write the starts with either right attribute the value whatever value
right attribute the value whatever value is having the same value for example the
is having the same value for example the start and the stop button right they
start and the stop button right they have the two words that is the st was
have the two words that is the st was the starting value our same right so we
the starting value our same right so we can use that so starts with is used in
can use that so starts with is used in that case the next we have the x path
that case the next we have the x path accesses that is a cell following
accesses that is a cell following following sibling ancestor proceeding
following sibling ancestor proceeding descendant parent and child these are
descendant parent and child these are the uh syntaxes of all these uh self and
the uh syntaxes of all these uh self and following which we study till now so you
following which we study till now so you can have uh you can study this and get a
can have uh you can study this and get a hang of it okay so this is a small cheat
hang of it okay so this is a small cheat sheet which i usually refer while
sheet which i usually refer while studying the expat so you can also check
studying the expat so you can also check it out so this is all for today
it out so this is all for today so this is all for today we learned
so this is all for today we learned about the xpath advanced expat we
about the xpath advanced expat we saw that practical implementation
saw that practical implementation with the static web page as well as a
with the static web page as well as a dynamic table that we have seen
dynamic table that we have seen so in this tutorial we will understand
so in this tutorial we will understand about the shadow dom objects so let's
about the shadow dom objects so let's get started
get started so before understanding about the shadow
so before understanding about the shadow dome let us understand what is dom
dome let us understand what is dom dom means document object model
dom means document object model so when the web page is loaded the
so when the web page is loaded the browser creates a tree of objects on the
browser creates a tree of objects on the web page and this tree is called as dom
web page and this tree is called as dom like in the previous tutorial i
like in the previous tutorial i explained dom is an api
explained dom is an api in which when the web page is loaded the
in which when the web page is loaded the browser creates a tree of objects on the
browser creates a tree of objects on the web page like here you can see we have
web page like here you can see we have the root element html then we have the
the root element html then we have the head we have title under the html we
head we have title under the html we have the body tag
have the body tag inside the body tag we have the h1 the a
inside the body tag we have the h1 the a tag and all these tags are inside the
tag and all these tags are inside the body tag right so this is a dom
body tag right so this is a dom structure that is the document object
structure that is the document object model structure for example
model structure for example for example this page and if i click on
for example this page and if i click on inspect
inspect and here you can see
this entire thing is your dom that is we're having the html head body and the
we're having the html head body and the div tags the input tags all this is your
div tags the input tags all this is your dom
dom we have the head we have the we have
we have the head we have the we have html we have head and the body tag in
html we have head and the body tag in the closing html tag so this is a dom
the closing html tag so this is a dom structure okay
structure okay now dom provides power to javascript to
now dom provides power to javascript to do some following things like they can
do some following things like they can change the elements of the page they can
change the elements of the page they can change the attributes of the element of
change the attributes of the element of the page we can add or remove elements
the page we can add or remove elements or attributes in a page we can create
or attributes in a page we can create new html events and we can react to
new html events and we can react to those events now how do we do that let
those events now how do we do that let me explain you with the help of an
me explain you with the help of an example
now uh for example suppose uh let me write html
write html if i write html over here
if i write html over here and i'll write the
and i'll write the body i'll give the body tag
body i'll give the body tag then i'll use the p tag i'll write a
then i'll use the p tag i'll write a text over here
text over here this
this is not shown this is my p tag
is not shown this is my p tag now let me run this and here the output
now let me run this and here the output is on the console that is this is not
is on the console that is this is not shown this is the output
shown this is the output now what if i write a javascript code
i will write my javascript code in my script tag
script tag so here i will write document
so here i will write document dot
dot get element
by id so i'll give an id over here in p tag
tag i will write an id over here i'll write
i will write an id over here i'll write it as x
it as x 1
1 so the id that i'm accessing over here
so the id that i'm accessing over here is
is x1
okay now i'll use a dom property that is the inner
the inner html
html is equal to
programming knowledge
okay now let's run this command
now let's run this command and here you can see the output is
and here you can see the output is welcome to programming knowledge
welcome to programming knowledge now what we can see over here is that
now what we can see over here is that welcome to programming knowledge is
welcome to programming knowledge is overriding this is not shown
overriding this is not shown okay what happens is when we write
okay what happens is when we write document.getelementbyid
document.getelementbyid it finds this id x1
it finds this id x1 and it uh changes this element that is
and it uh changes this element that is this is not shown is changed to welcome
this is not shown is changed to welcome to programming knowledge
to programming knowledge okay
okay so this is what is happening over here
so this is what is happening over here so dom provides the power to javascript
so dom provides the power to javascript to change the element to change the
to change the element to change the attributes of the element we can add or
attributes of the element we can add or remove the elements of the web page and
remove the elements of the web page and we can create new html events as well
we can create new html events as well what is the need of shadow dom like in
what is the need of shadow dom like in the previous slide i explained that dom
the previous slide i explained that dom provides
provides power to the
power to the javascript to change the lms right now
javascript to change the lms right now there are websites that require some web
there are websites that require some web components developed by others that
components developed by others that contains the html css in javascript code
contains the html css in javascript code what are these web components for
what are these web components for example
like this is the online id that i'm having and here you can see these
having and here you can see these advertisements right here you can see
advertisements right here you can see these ads
these ads these ads are controlled by some other
these ads are controlled by some other site
site okay
okay and you can see this is facebook so this
and you can see this is facebook so this is controlled by the facebook site
is controlled by the facebook site similarly over here if you can see we
similarly over here if you can see we have different types of ads over here
have different types of ads over here like here you can see this dell ad
like here you can see this dell ad also if you're looking some other pages
also if you're looking some other pages like hurry also you can see this is the
like hurry also you can see this is the microsoft exchange this is also
microsoft exchange this is also controlled by some other site
controlled by some other site all these ads are controlled by some
all these ads are controlled by some other side
other side so what you're saying is that these are
so what you're saying is that these are the web components that is developed by
the web components that is developed by others that contains the html css and
others that contains the html css and javascript code now for example over
javascript code now for example over here this this thing that you can see
here this this thing that you can see this web component is having an html css
this web component is having an html css or javascript code
or javascript code now when i integrate with my code this
now when i integrate with my code this is the code that i am having obviously
is the code that i am having obviously as i said dom is giving the
as i said dom is giving the ability to javascript to change the
ability to javascript to change the elements right so what if all the code
elements right so what if all the code that is written over here in this
that is written over here in this javascript is changing the code that is
javascript is changing the code that is written over here in the html
written over here in the html it's harmful right so that's the reason
it's harmful right so that's the reason why we are using shadow dom
over here the objective is that people want to use
the objective is that people want to use this web component of others but they
this web component of others but they don't want their invo they don't want to
don't want their invo they don't want to impact the sites
impact the sites so how do we integrate a web component
so how do we integrate a web component from other developer
from other developer so that they cannot access my component
so that they cannot access my component so that their component my components
so that their component my components don't interfere how do we do that the
don't interfere how do we do that the solution is the shadow dom and iframes
solution is the shadow dom and iframes now iframe is something different for
now iframe is something different for example suppose if i give something uh
example suppose if i give something uh some
some iframe some functionality is presented
iframe some functionality is presented over here there is some functionality
over here there is some functionality over here
this is functionality one and there's another iframe that i have
there is some functionality too
so whatever changes that i perform in functionality one will not affect the
functionality one will not affect the changes in the functionality too
changes in the functionality too that is the feature of iframe okay this
that is the feature of iframe okay this is one feature of iframe uh we will
is one feature of iframe uh we will study about iframe in detail but for now
study about iframe in detail but for now to understand whatever functionality uh
to understand whatever functionality uh whatever changes i do in functionality
whatever changes i do in functionality one will not affect the changes in the
one will not affect the changes in the functionality too this is what iframe is
functionality too this is what iframe is okay
okay coming to the next is shadow dom
coming to the next is shadow dom now what is shadow dom
now what is shadow dom since we have understood the need of
since we have understood the need of shadow dom we have understood what is
shadow dom we have understood what is dom and how does dom uh provide the
dom and how does dom uh provide the power to the javascript to change
power to the javascript to change elements so we have understood what is
elements so we have understood what is the need but what is dom this is the
the need but what is dom this is the definition
definition shadow dom is a web standard that
shadow dom is a web standard that developers use to encapsulate their html
developers use to encapsulate their html code and style components
code and style components so that no the style component can
so that no the style component can overwrite their code
overwrite their code for example
for example for example suppose so we are working in
for example suppose so we are working in a group we are working in a group of
a group we are working in a group of four to five people and there's a
four to five people and there's a project and everyone is working on
project and everyone is working on different different functionality so let
different different functionality so let us take up suppose
us take up suppose there's a use of one
there's a use of one so this user is developing some
so this user is developing some functionality and i'll just write a code
functionality and i'll just write a code for it suppose uh div class
for it suppose uh div class is equal to i'll write it
is equal to i'll write it v
v and i'll write h1 tag over here
and i'll write h1 tag over here and i'll write a
hello world
world okay
okay and i'll write some styling over here
and i'll write some styling over here i'll give some styling so since it's a
i'll give some styling so since it's a class so dot v
and i'll write some color
some color and i'll give color as red
and i'll give color as red let's run this
let's run this so here the output is hello world in red
so here the output is hello world in red color okay this is the user one score
color okay this is the user one score now uh the user one is not knowing what
now uh the user one is not knowing what the user two is coding they are working
the user two is coding they are working in group but differently right someone
in group but differently right someone is working for some other functionality
is working for some other functionality someone is working with some other
someone is working with some other functionality so this is the first
functionality so this is the first functionality which the user one created
functionality which the user one created so i'll just comment this for now and
so i'll just comment this for now and let's see the next example
so the next user develop some of the functionality let's
develop some of the functionality let's see some other functionality and uh
see some other functionality and uh i'll just write a code of it i'll write
i'll just write a code of it i'll write div
div i'll write class
i'll write class and now the user two does not know what
and now the user two does not know what the user one has coded so
the user one has coded so there might be a chance that they have
there might be a chance that they have named the class similar so i'll name the
named the class similar so i'll name the class as v itself then i'll write the in
class as v itself then i'll write the in h2 tag
i'll write hello
hello user 2
user 2 okay
okay and i'll write some code for css
because it's a class so i'll access by a dot v
dot v and i'll write
and i'll write color
i'll give it as green
green okay
okay so let's see here the output is for the
so let's see here the output is for the user too
user too now since we are working in a project
now since we are working in a project and we need to present it so we will
and we need to present it so we will integrate the code okay user1 and user2
integrate the code okay user1 and user2 are integrating their codes so what will
are integrating their codes so what will happen
happen for example the user1 and user2 has
for example the user1 and user2 has integrated their code now what will
integrated their code now what will happen
happen as we know for user one our output was
as we know for user one our output was hello world in red color and for user 2
hello world in red color and for user 2 our output was hello user 2 in green
our output was hello user 2 in green color
color so now
so now after integrating let's see what the
after integrating let's see what the output is
output is it's hello world in green color
it's hello world in green color it's hello user 2 in green color which
it's hello user 2 in green color which means
means this css style is overriding this css
this css style is overriding this css style right
style right that's what is the definition of shadow
that's what is the definition of shadow dom
dom shadow dom is a web standard that
shadow dom is a web standard that developers use to encapsulate their html
developers use to encapsulate their html code and css components style components
code and css components style components means css components
means css components they are encapsulating their html code
they are encapsulating their html code and css components so that no other css
and css components so that no other css component can overwrite their code
component can overwrite their code now in this case
now in this case if user1 has given class v so there
if user1 has given class v so there might be many classes of class we write
might be many classes of class we write of name v there would be very many
of name v there would be very many classes of name v
classes of name v all those v classes will get overrided
all those v classes will get overrided by green color right the entire text
by green color right the entire text will be a green color so here the css
will be a green color so here the css style is overriding
style is overriding right so this is the definition of
right so this is the definition of shadow dome
shadow dome so when we try to find shadow dome
so when we try to find shadow dome elements using the selenium locators it
elements using the selenium locators it will throw no such element exception
will throw no such element exception okay now how do we identify it is a
okay now how do we identify it is a shadow dom object for example
i have this website this website is having the shadow dom elements so if i
having the shadow dom elements so if i want to inspect this element i'll click
want to inspect this element i'll click on inspect
on inspect and here you can see this shadow root
and here you can see this shadow root open
open this shadow root open is used to
this shadow root open is used to denote the shadow dom object
denote the shadow dom object so uh another thing that we can see over
so uh another thing that we can see over here is if i see in selectors hub here
here is if i see in selectors hub here it is it is in blue color that is in
it is it is in blue color that is in shadow dom it is here written over here
shadow dom it is here written over here so this means that this element is a
so this means that this element is a shadow dom element here it is written
shadow dom element here it is written the element inside the shadow dom and
the element inside the shadow dom and for such elements xpath won't support
for such elements xpath won't support yes for shadow dom elements uh xpath
yes for shadow dom elements uh xpath will not support we need to inspect
will not support we need to inspect these elements through css selectors
these elements through css selectors okay
okay now let me give an example like suppose
now let me give an example like suppose this is also a website which is having
this is also a website which is having the shadow dom elements so if i want to
the shadow dom elements so if i want to inspect this element i'll click on
inspect this element i'll click on inspect
inspect and since you here you can see we have
and since you here you can see we have shadow root open shadow root open shadow
shadow root open shadow root open shadow root open so this is a shadow dom object
root open so this is a shadow dom object okay
okay let me open my selectors hub and here
let me open my selectors hub and here you can see we have this element is
you can see we have this element is inside shadow dom object and in such
inside shadow dom object and in such elements x path is not supported now
elements x path is not supported now what if we give an x path if i want to
what if we give an x path if i want to inspect this element let's see what
inspect this element let's see what error do we find so i have already
error do we find so i have already created a selenium tutorials nine java
created a selenium tutorials nine java class over here in which we have the
class over here in which we have the first command is open the chrome browser
first command is open the chrome browser in which we have system dot set property
in which we have system dot set property the key and the value is given over here
the key and the value is given over here next we have written web driver driver
next we have written web driver driver is equal to new chrome driver to launch
is equal to new chrome driver to launch the chrome driver
the chrome driver next we are navigating to the url this
next we are navigating to the url this is the url that we are navigating to and
is the url that we are navigating to and this is the element that we want to
this is the element that we want to inspect so we will write a expert
inspect so we will write a expert expert for this element okay
expert for this element okay let's see
let's see then i'm maximizing the window and this
then i'm maximizing the window and this is the expert that i have written over
is the expert that i have written over here
here like i've written driver dot find
like i've written driver dot find element by dot xpath
element by dot xpath two slashes and the tag that i'm using
two slashes and the tag that i'm using is the input tag
is the input tag here you can see we have input tag also
here you can see we have input tag also sele the
sele the attribute that i'm using is the id
attribute that i'm using is the id attribute and the value of it is input
attribute and the value of it is input so the id attribute and the value is
so the id attribute and the value is input and i'm sending some command as
input and i'm sending some command as testing so let's see if we can run this
testing so let's see if we can run this code
code and what error do we find so
can you see some text over here no right so here there's an error let's see what
so here there's an error let's see what that error is
that error is we have no such element exception that
we have no such element exception that is no such element unable to locate this
is no such element unable to locate this element
element we are unable to locate this element
we are unable to locate this element this is shown over here this is the
this is shown over here this is the error that we are getting and there is
error that we are getting and there is no text sent over here do you see any
no text sent over here do you see any text no right there is no text sent over
text no right there is no text sent over here so it says that is unable to locate
here so it says that is unable to locate element so whenever we locate we try to
element so whenever we locate we try to locate the shadow dome elements this is
locate the shadow dome elements this is the error that we find that is the no
the error that we find that is the no such element
such element exception is given over here and shadow
exception is given over here and shadow domes does not support the x path okay
domes does not support the x path okay we have to use a css selector to access
we have to use a css selector to access shadow dom objects
shadow dom objects also to access shadow dom elements we
also to access shadow dom elements we need to use we have to use the
need to use we have to use the javascript executor we will understand
javascript executor we will understand that by implementing it
next there are some terminologies in shadow dom while inspecting the element
shadow dom while inspecting the element while
while identifying it these terminologies will
identifying it these terminologies will be used
be used one is the shadow horse that is the
one is the shadow horse that is the regular dom node that the shadow dom is
regular dom node that the shadow dom is attached to this is the shadow host
attached to this is the shadow host right it is the regular dom node that
right it is the regular dom node that the shadow dom is attached the shadow
the shadow dom is attached the shadow dom is attached to shadow host
dom is attached to shadow host next we have the shadow tree
next we have the shadow tree the dom tree inside the shadow dome this
the dom tree inside the shadow dome this is the shadow tree that we are having
is the shadow tree that we are having here you can see this highlighted part
here you can see this highlighted part this is the shadow trees that we are
this is the shadow trees that we are having
having it is a dorm tree inside the shadow dom
it is a dorm tree inside the shadow dom inside the shadow dome these are the dom
inside the shadow dome these are the dom trees
trees next we have the shadow boundary here
next we have the shadow boundary here you can see this is the shadow boundary
you can see this is the shadow boundary this is a place where the shadow dome
this is a place where the shadow dome ends and the regular dome begins okay so
ends and the regular dome begins okay so this is the place where the shadow dome
this is the place where the shadow dome ends and the regular dome begins
ends and the regular dome begins next we have the shadow root that is the
next we have the shadow root that is the root node of the shadow tree now this is
root node of the shadow tree now this is the most important element that we are
the most important element that we are going to inspect like suppose if you
going to inspect like suppose if you want to inspect this element we will
want to inspect this element we will inspect the shadow root we will inspect
inspect the shadow root we will inspect the shadow host so we will understand
the shadow host so we will understand that but for now these are some of the
that but for now these are some of the terminologies that is used in the shadow
terminologies that is used in the shadow dom structure
dom structure so uh now how to identify it like i have
so uh now how to identify it like i have showed you before like we have the
showed you before like we have the shadow root written over here that means
shadow root written over here that means it is a shadow dom object also if we go
it is a shadow dom object also if we go on selectors huh so over there there it
on selectors huh so over there there it has a feature it shows in blue color
has a feature it shows in blue color letters in shadow dome it also gives a
letters in shadow dome it also gives a information about that relative x path
information about that relative x path is not supported that is this element is
is not supported that is this element is in shadow dome and for such elements
in shadow dome and for such elements xpath is not supported
xpath is not supported so this is one way to identify the
so this is one way to identify the shadow dom object now next we will
shadow dom object now next we will understand its implementation let us do
understand its implementation let us do a practical implementation on it so this
a practical implementation on it so this is the website that we need to automate
is the website that we need to automate and this is the element that i am
and this is the element that i am inspecting
inspecting so i want to enter some value over here
so i want to enter some value over here any value i want to enter so this is the
any value i want to enter so this is the element
element now before writing the code for it we
now before writing the code for it we need to understand the elements that are
need to understand the elements that are under shadow dom and which are not under
under shadow dom and which are not under shadow dom okay
shadow dom okay so
so this is the dom structure which we have
this is the dom structure which we have this is the entire dom structure we need
this is the entire dom structure we need to understand it first
to understand it first this is the element that we want to
this is the element that we want to inspect
inspect okay which is not under shadow root the
okay which is not under shadow root the elements that are under shadow root is
elements that are under shadow root is style div div slot name these are the
style div div slot name these are the elements that is present under shadow
elements that is present under shadow root
root this input is under book input decorator
this input is under book input decorator top okay
top okay this book input decorator top is not
this book input decorator top is not under the shadow root if you are
under the shadow root if you are thinking this is under shadow root
thinking this is under shadow root because the shadow root is written over
because the shadow root is written over here no
here no if we click on this we can see the style
if we click on this we can see the style and the slot tags are under the shadow
and the slot tags are under the shadow root but the book input deck or top is
root but the book input deck or top is not under the shadow root okay
not under the shadow root okay so this book input decor top is under
so this book input decor top is under the app toolbar
the app toolbar so
so this book input decker top is under the
this book input decker top is under the app toolbar and this app toolbar is not
app toolbar and this app toolbar is not under the shadow root
under the shadow root can you see anything can you see the
can you see anything can you see the shadow root the shadow root is present
shadow root the shadow root is present over here in which we have the style and
over here in which we have the style and the div tags okay so this app toolbar is
the div tags okay so this app toolbar is not present under the shadow root
not present under the shadow root this book input echo is
this book input echo is present into app toolbar
present into app toolbar okay
okay next this app toolbar is present under
next this app toolbar is present under the app header this is the app header
the app header this is the app header okay
okay which is inside the shadow root here you
which is inside the shadow root here you can see the shadow root now if i click
can see the shadow root now if i click on this we can see app header right
on this we can see app header right so app header is under the shadow root
so app header is under the shadow root and then we have the app book which is
and then we have the app book which is the host
the host here we can see the root element and
here we can see the root element and this is the host element
this is the host element right so first we will go on app book we
right so first we will go on app book we will inspect the app book then we will
will inspect the app book then we will enter the shadow root element
enter the shadow root element after entering the shadow root
after entering the shadow root we will move to app header
we will move to app header after app header we will go on app
after app header we will go on app toolbar
toolbar after app toolbar we will go on book
after app toolbar we will go on book input decor and after in book input
input decor and after in book input record we will inspect this element okay
record we will inspect this element okay this is the element that we want to
this is the element that we want to inspect
inspect right so this will be the entire process
right so this will be the entire process the first thing is that we have to
the first thing is that we have to identify the host
identify the host this is our host this is the root
this is our host this is the root element right
element right so first we will inspect the app book
so first we will inspect the app book then we will enter the dom element
then we will enter the dom element inside the dom element first we will
inside the dom element first we will enter the app header
enter the app header after app header we will inspect the app
after app header we will inspect the app toolbar and after app toolbar we will
toolbar and after app toolbar we will inspect the book input decor and then we
inspect the book input decor and then we will inspect the inputs uh tag okay
will inspect the inputs uh tag okay okay so this is the element that we want
okay so this is the element that we want to inspect
to inspect right this input is the element that we
right this input is the element that we want to inspect
want to inspect this input is under book input
this input is under book input okay
okay this book input is under the app toolbar
this book input is under the app toolbar and this app toolbar is under the app
and this app toolbar is under the app header
header okay
okay this app header is under the shadow root
this app header is under the shadow root this is our route
this is our route and this is our host
and this is our host and this is our host so the first thing
and this is our host so the first thing that we will inspect is this the host
that we will inspect is this the host this is the second thing we will do we
this is the second thing we will do we will enter the dom
will enter the dom inside dom this is the third thing that
inside dom this is the third thing that we will inspect that is the app header
we will inspect that is the app header after app header we will go on app
after app header we will go on app toolbar this is the fourth thing that we
toolbar this is the fourth thing that we will inspect
will inspect after app toolbar we will inspect the
after app toolbar we will inspect the book input record this is the fifth
book input record this is the fifth thing
thing and the sixth one is the input slot
and the sixth one is the input slot over here we will send the commands
over here we will send the commands because it's the search box we want to
because it's the search box we want to send some command to it so after all
send some command to it so after all these steps we can inspect this so this
these steps we can inspect this so this is the entire thing that we're going to
is the entire thing that we're going to implement now
implement now first we will inspect the host
first we will inspect the host then we will enter the root the shadow
then we will enter the root the shadow root after entering the shadow root over
root after entering the shadow root over here we will use a javascript executor
here we will use a javascript executor after here over here after this
after here over here after this we will access the app header
we will access the app header after app header we will access the
after app header we will access the app toolbar we will inspect the app app
app toolbar we will inspect the app app toolbar after that we will inspect the
toolbar after that we will inspect the book input record and then we can move
book input record and then we can move on to input okay so this is the entire
on to input okay so this is the entire process that we're going to follow
process that we're going to follow so
so let's do that
let's do that so first let's inspect the host
so first let's inspect the host we will write a driver
we will write a driver dot
dot find element
find element by dot
by dot tag name
tag name over here we're going to write
this is our host right so we are inspecting our host
inspecting our host the tag name is book app
so i will write book app over here this is a web element
this is a web element i'll write web element
i'll write web element host
host is equal to driver dot find element by
is equal to driver dot find element by dot tag name okay
dot tag name okay next we will enter the dom
next we will enter the dom okay for that we need to write
okay for that we need to write javascript executor
javascript executor j
j is equal to
is equal to driver
driver because this driver
because this driver is of web driver driver is equal to new
is of web driver driver is equal to new chrome driver
chrome driver so i'm going to write
so i'm going to write i'm going to typecast it so i'll write
i'm going to typecast it so i'll write javascript executor driver okay
javascript executor driver okay next i'm going to do j dot
next i'm going to do j dot execute script which accepts two
execute script which accepts two arguments one is the string and one is
arguments one is the string and one is the object argument so here in string i
the object argument so here in string i will write
will write return
return arguments
arguments the zeroth one
the zeroth one and where do i want to enter is i want
and where do i want to enter is i want to enter to shadow root right
to enter to shadow root right so i'll write the shadow root the zero
so i'll write the shadow root the zero shadow root uh shadow root is present in
shadow root uh shadow root is present in the host element right so i'll write
the host element right so i'll write comma host
comma host okay
now i'll give this a web element
web element i'll write
i'll write shadow dom
shadow dom is equal to
says we need to cast it to web element now just because this is of javascript
now just because this is of javascript executed type we need to cast it to web
executed type we need to cast it to web element because i want to inspect web
element because i want to inspect web elements over here okay
elements over here okay now whatever we're going to do we're
now whatever we're going to do we're going to do inside the shadow dom
going to do inside the shadow dom okay
okay this is the shadow dom we inspected the
this is the shadow dom we inspected the host element we are
host element we are and we inspected the shadow root element
and we inspected the shadow root element so we are inside shadow root now now
so we are inside shadow root now now inside shadow root inside the shadow
inside shadow root inside the shadow root what i want to inspect is app
root what i want to inspect is app header now okay so what i'm going to do
header now okay so what i'm going to do is
is this is the app header
this is the app header i will write
i will write shadow
shadow dom
dom dot
dot find element
find element by dot
tag name and inside the tag name i will write
write app header
and i will give it as a web element
app header okay
okay so so far uh we have inspected our host
so so far uh we have inspected our host we are into our dom element also we have
we are into our dom element also we have inspected the
inspected the app header
app header now we are left with the app toolbar the
now we are left with the app toolbar the book input decorator and then the input
book input decorator and then the input slot
slot so after navigating to app header we
so after navigating to app header we need to enter the app toolbar okay so
need to enter the app toolbar okay so what i'm going to do is
i will write app header dot
find element by dot
now this app toolbar there are two app toolbars here you can see this one and
toolbars here you can see this one and this one right so here the class name is
this one right so here the class name is different so we will access by class so
different so we will access by class so we will use the css selector over here
we will use the css selector over here so i'll write by dot css selector
so i'll write by dot css selector and then i'll write
and then i'll write input oh and then sorry i'll write
because it's a class so i'll write dot and the toolbar bottom
okay so this is my tag name and this is my class
my class i'll give a web element
i'll give a web element i'll name it as
i'll name it as app
app tool
so so far we have navigated to host we have
we have navigated to host we have inspected our host then we came into our
inspected our host then we came into our dom element after that we navigated to
dom element after that we navigated to app header
app header and after which we came to app toolbar
and after which we came to app toolbar this is the app toolbar that we key
this is the app toolbar that we key now inside the app toolbar we want to go
now inside the app toolbar we want to go to the book input decorator so we're
to the book input decorator so we're going to write
going to write this is the book input
dot find element
tag name and i'll write the tag name over here
i'll give this a web element i'll write a web element for your web
i'll write a web element for your web element
element book
book is equal to app tool dot fine element
is equal to app tool dot fine element okay
okay so now we will inspect our element that
so now we will inspect our element that is the input tag
is the input tag so what we're going to do is we'll write
so what we're going to do is we'll write book
book dot
dot find element or let us use a css
find element or let us use a css selector so i will use the css selector
selector so i will use the css selector i'll write
so we can use this is the tag and the id that we have
this is the tag and the id that we have is input so i'll use input input
input because it's a id so hash input and what value do i want to send i want
and what value do i want to send i want to send
to send some key to it i will send
some key to it i will send selenium web
selenium web driver
okay so let's run this
let's maximize and here you can see that the command is sent that is the selenium
the command is sent that is the selenium webdriver
webdriver okay
so uh this is what is shadow dom is
is shadow dom is as i said
as i said first we need to find the host element
first we need to find the host element so our host element was book app then we
so our host element was book app then we entered the shadow dom
entered the shadow dom after entering the shadow dom we have to
after entering the shadow dom we have to inspect the app header after app header
inspect the app header after app header we inspected the app toolbar after which
we inspected the app toolbar after which we inspected the book input decorator
we inspected the book input decorator and then we inspected the input tag
and then we inspected the input tag so here you see
so here you see uh first we need to understand the dom
uh first we need to understand the dom structure before writing a code for the
structure before writing a code for the uh shadow dom we need to understand
uh shadow dom we need to understand which elements are under shadow dom and
which elements are under shadow dom and which elements are not under shadow dog
which elements are not under shadow dog so this is one way
so this is how we're going to do it now there are different sites where you can
there are different sites where you can practice
practice shadow dom like you can
shadow dom like you can use the chrome download page as well
use the chrome download page as well this download page is also having
this download page is also having shadow root elements for example like if
shadow root elements for example like if you want to inspect this
you want to inspect this download here you can see we have shadow
download here you can see we have shadow root elements this is the shadow root
root elements this is the shadow root this is shadow road this is shadow root
this is shadow road this is shadow root also uh there are different ways
also uh there are different ways websites like um
websites like um let me show you one
let me show you one like this is the website that is there
like this is the website that is there for shadow dom practice like all the
for shadow dom practice like all the elements that are present over here are
elements that are present over here are of shadow dom
of shadow dom here we have shadow root we have shadow
here we have shadow root we have shadow roof we have shadow roots so you can
roof we have shadow roots so you can have a hang you can
have a hang you can practice on this website also
practice on this website also so i'll give all these links in the
so i'll give all these links in the description so you can get a hang of it
description so you can get a hang of it so in the previous tutorial we learnt
so in the previous tutorial we learnt about the shadow dom objects in this
about the shadow dom objects in this tutorial we are going to understand some
tutorial we are going to understand some of the important selenium commands which
of the important selenium commands which is frequently used to write the test
is frequently used to write the test scripts
scripts now these selenium commands consist of
now these selenium commands consist of the browser commands the navigation
the browser commands the navigation commands and the web element commands
commands and the web element commands today we are going to understand the
today we are going to understand the browser commands like what are browser
browser commands like what are browser commands what are the different types of
commands what are the different types of browser commands with their syntax also
browser commands with their syntax also we will implement some set of test cases
we will implement some set of test cases and then we will understand the
and then we will understand the difference between the close method and
difference between the close method and the quick method so let's get started
the quick method so let's get started now first let us understand what are
now first let us understand what are browser commands
browser commands browser commands are something that are
browser commands are something that are very basic operations of the web driver
very basic operations of the web driver which includes the closing of the
which includes the closing of the browser performing some few tasks to see
browser performing some few tasks to see you task is like get title
you task is like get title to
to quit to manage to close the browser to
quit to manage to close the browser to get the current url to get the page
get the current url to get the page source so these are some of the uh
source so these are some of the uh operations these are some of the few
operations these are some of the few tasks that we perform on the selenium
tasks that we perform on the selenium webdriver
webdriver so and these are some of the list that
so and these are some of the list that is given over here
is given over here this is the list that is given over here
this is the list that is given over here now if you write for example
now if you write for example if i write driver dot
if i write driver dot you can see this list so these are the
you can see this list so these are the different this list which is getting
different this list which is getting highlighted over here so these are the
highlighted over here so these are the different browser commands that is
different browser commands that is present over here okay so these are
present over here okay so these are browser commands
browser commands now i have just created this basic uh
now i have just created this basic uh uh notes
uh notes this basic sheet which consists of the
this basic sheet which consists of the browser commands the navigational
browser commands the navigational commands the web element commands which
commands the web element commands which consists of the commands the description
consists of the commands the description the syntax and what parameters accepts
the syntax and what parameters accepts and what it returns
and what it returns it will be very quick recap for you
it will be very quick recap for you while going in interviews because they
while going in interviews because they frequently ask these questions like what
frequently ask these questions like what is the difference between the close the
is the difference between the close the quit method the submit and the click
quit method the submit and the click method
method and what is the difference between find
and what is the difference between find element and find elements so these are
element and find elements so these are some of the differences which we will
some of the differences which we will cover
cover and also we will study these commands so
and also we will study these commands so uh
uh this is the sheet that i have prepared i
this is the sheet that i have prepared i will give the link of this sheet in the
will give the link of this sheet in the description box you can download the pdf
description box you can download the pdf format also i have uploaded on my drive
format also i have uploaded on my drive so i will give the link of this drive as
so i will give the link of this drive as well so you can get a hang of all those
well so you can get a hang of all those commands whenever you go for interviews
commands whenever you go for interviews now coming to the test cases
now coming to the test cases these are the test cases which we will
these are the test cases which we will execute
execute and while executing we will cover these
and while executing we will cover these commands
commands these are the commands like the get the
these are the commands like the get the get title the get current url to get
get title the get current url to get paid source to close and the quit
paid source to close and the quit now get window handle and get window
now get window handle and get window handles is a part of the browser command
handles is a part of the browser command but it is a bit complicated
but it is a bit complicated i will cover that in the later tutorial
i will cover that in the later tutorial so for now we need to get a hang of get
so for now we need to get a hang of get get title get current url get paid
get title get current url get paid source close and quick so by executing
source close and quick so by executing these test cases we will create the test
these test cases we will create the test scripts of these test cases we will
scripts of these test cases we will understand these commands also okay
understand these commands also okay first test case that we have is the open
first test case that we have is the open the chrome browser
the chrome browser okay in which we use the system dot sell
okay in which we use the system dot sell property
property and uh
and uh the web driver driver is equal to new
the web driver driver is equal to new chrome driver these are the two commands
chrome driver these are the two commands that we use in opening the chrome
that we use in opening the chrome browser
browser then navigate to the url to navigate to
then navigate to the url to navigate to the url we use the
the url we use the drive.driver.getcommand right so this is
drive.driver.getcommand right so this is the part of the browser command next we
the part of the browser command next we will maximize the window
will maximize the window the next we will verify the current url
the next we will verify the current url of the page for this we will use the
of the page for this we will use the current
current get current url command okay
get current url command okay through if statement
through if statement okay then we have to verify the title of
okay then we have to verify the title of the page now to verify the title of the
the page now to verify the title of the page we will use the get title command
page we will use the get title command okay and we will verify it through if
okay and we will verify it through if statement
statement next we will print the length of the
next we will print the length of the title of the page and this we will use
title of the page and this we will use the length command we'll have a look at
the length command we'll have a look at that okay next we will print the page
that okay next we will print the page source of the page
source of the page in which we will use the get page source
in which we will use the get page source command also we will print the length of
command also we will print the length of the page source okay
the page source okay next we have to close the browser and
next we have to close the browser and quit the browser now uh we will
quit the browser now uh we will understand the difference also uh
understand the difference also uh practically okay so this is the webpage
practically okay so this is the webpage that i want to automate today now i have
that i want to automate today now i have created a
created a java class in my
java class in my package combat selenium in which i have
package combat selenium in which i have named it as selenium tutorials then i'll
named it as selenium tutorials then i'll be executing my test scripts over here
be executing my test scripts over here in this in this selenium tutorial 10 the
in this in this selenium tutorial 10 the first test case was to open the chrome
first test case was to open the chrome browser for which we use the system.set
browser for which we use the system.set properties
properties in which we give the key and the value
in which we give the key and the value the key is the webdriver.chrome.driver
the key is the webdriver.chrome.driver and the value is the executable chrome
and the value is the executable chrome driver file okay
driver file okay next we have the web driver driver is
next we have the web driver driver is equal to new chrome driver
equal to new chrome driver why do we write the statement i have
why do we write the statement i have explained in the previous tutorial you
explained in the previous tutorial you can have a look at that tutorial
can have a look at that tutorial okay the next command is that we have to
okay the next command is that we have to navigate to the url
navigate to the url so what i'll do is i'll write driver
so what i'll do is i'll write driver dot
dot get
get and i will write my url in this get
and i will write my url in this get this is
this is the first method okay to navigate to the
the first method okay to navigate to the url
the second method that you can do or you can
can navigate is
navigate is i can assign the url to a string
i can assign the url to a string variable
variable like i'll write string
like i'll write string i will name that variable as url
i will name that variable as url and i will place my url in this
and i will place my url in this variable
variable next i will write driver
next i will write driver dot get
dot get url
url so i can navigate to the url through
so i can navigate to the url through this way as well as this way both the
this way as well as this way both the ways it will work for example so let's
ways it will work for example so let's see
see whether we can navigate or not so by
whether we can navigate or not so by using this method driver dot get method
okay so chrome browser is launched and also it is navigated to this
also it is navigated to this page
page i will
i will comment this and let's see
okay so i chrome browser is also known so net is also navigated
so net is also navigated so these are the two methods to which
so these are the two methods to which you can navigate to the url
you can navigate to the url now get method
now get method i will just comment this for now we will
i will just comment this for now we will use this driver.get method now uh get my
use this driver.get method now uh get my turn on this commands open the specified
turn on this commands open the specified url in the browser it accepts string as
url in the browser it accepts string as a parameter and it returns nothing okay
a parameter and it returns nothing okay and this is the basic syntax of
and this is the basic syntax of navigating to the url and it is a part
navigating to the url and it is a part of the browser command
of the browser command so next test case that we have
so next test case that we have is to maximize the window
is to maximize the window so i'll write driver
so i'll write driver dot
dot manage
manage dot window
dot window dot
dot maximize
maximize okay so the next command is
okay so the next command is verify the current url of the page
verify the current url of the page url of the page
url of the page let's first find the url and then we
let's first find the url and then we will verify
will verify so i'll write driver
so i'll write driver dot
dot get current url
get current url and i will store this in a
and i will store this in a string variable
string url of the page
url of the page and i will print this
okay let's see what is the output
and here it is the url of the pages this this is the url of the page
this this is the url of the page now let's verify the url
now let's verify the url to verify the url we will use the if
to verify the url we will use the if statement so i will write if
statement so i will write if url of the page
url of the page dot equals
dot equals now i will write
now i will write the url over here
now if i was uh executing this statement this navigation statement what would i
this navigation statement what would i do what did i do over here is that i
do what did i do over here is that i have written string url right so what
have written string url right so what would i do over here i will simply write
would i do over here i will simply write url
okay so this means that the url of the page
so this means that the url of the page that is the output that we are getting
that is the output that we are getting the actual output and the expected
the actual output and the expected output
output will be matched the expected output is
will be matched the expected output is this this which is stored in this url
this this which is stored in this url variable and the actual output is stored
variable and the actual output is stored in the url of the page right so if i
in the url of the page right so if i would execute this statement i would
would execute this statement i would have written this way but since i'm
have written this way but since i'm executing driver.getcommand i'm not
executing driver.getcommand i'm not writing it this way i'm not storing it
writing it this way i'm not storing it in a string variable and then
in a string variable and then writing driver.get and inside get i'm
writing driver.get and inside get i'm writing the url the parameter that i'm
writing the url the parameter that i'm giving is the url that is a string
giving is the url that is a string parameter
parameter so i'm not executing it this way i'm
so i'm not executing it this way i'm executing through driver.getcommand so
executing through driver.getcommand so i'm not writing it this way so i'll just
i'm not writing it this way so i'll just simply write what output do i want this
simply write what output do i want this is the expected output that i'm writing
is the expected output that i'm writing over here and the actual output that i'm
over here and the actual output that i'm getting is the url of the page okay
getting is the url of the page okay [Music]
[Music] now if the actual and the expected
now if the actual and the expected matches so what i want is
matches so what i want is i want the output as
the url is
is verified
and then else i want
the url is not
not verified so now let's execute this
verified so now let's execute this so my chrome browser is launched it's
so my chrome browser is launched it's navigated
navigated it's maximized
it's maximized and now let's see the url of the pages
and now let's see the url of the pages this is the url and the url is verified
this is the url and the url is verified that means the
that means the actual url that we are getting that is
actual url that we are getting that is this and the expected view url
this and the expected view url that is this both is matching okay
that is this both is matching okay this is the expected url and this is the
this is the expected url and this is the actual url both are matching that's the
actual url both are matching that's the reason why we have called the url is
reason why we have called the url is verified
verified for example if i just
for example if i just write it this way now let's see if it
write it this way now let's see if it works
so my chrome browser is launched it's navigated
it's maximized okay and here you can see the url is not
okay and here you can see the url is not verified why
verified why because my actual that is this is my
because my actual that is this is my actual
actual and the expected is not matching that's
and the expected is not matching that's the reason why the output is the url is
the reason why the output is the url is not verified
not verified the next test case is verify the title
the next test case is verify the title of the page
of the page so first we will find the title of the
so first we will find the title of the page
page so i'll write driver
so i'll write driver dot
dot get
get title
title and i will store this in a string
and i will store this in a string variable
variable i will write string
i will write string title is equal to driver dot cat title
title is equal to driver dot cat title next i will print it
next i will print it so let's execute it
so let's execute it my chrome browser is
launched so here it is see this is the url of the page the url is verified and
url of the page the url is verified and then here the title of the page is tools
then here the title of the page is tools qa this is the title of the page now how
qa this is the title of the page now how do you see the title of the pages so
do you see the title of the pages so i'll just inspect
and you're in the head tag here you can see you can see title tools
here you can see you can see title tools qa title this is the title of the page
qa title this is the title of the page this is the title of the page
this is the title of the page and the title that we got is the tools
and the title that we got is the tools qa so this is how you can find the title
qa so this is how you can find the title of the page on the
of the page on the web page okay next we have to verify the
web page okay next we have to verify the title right
title right so
so i'll use the if statement
i'll use the if statement i'll write if
i'll write if title
okay so this is the title let me copy this
and the output that i want if the actual and the
output that i want if the actual and the expected is matching
the title is verified
the title is not
is not verified
okay so here uh we are verifying the title of
so here uh we are verifying the title of the page so let's see let's see the
the page so let's see let's see the output of it
output of it so my chrome browser is launched
it's navigated
navigated it's maximized
it's maximized and here you can see the title is
and here you can see the title is verified because the expected output and
verified because the expected output and the actual output is matching
the actual output is matching okay
okay so now next test case that we have is we
so now next test case that we have is we need to print the length of the title of
need to print the length of the title of the page okay to print the length of the
the page okay to print the length of the title of the page
title of the page we're going to use the length command so
we're going to use the length command so what i'm going to do is i'm going to
what i'm going to do is i'm going to write
write driver
driver dot
dot get title dot
get title dot length
length okay and i will store it in the integer
okay and i will store it in the integer type of variable
type of variable because the answer that we're going to
because the answer that we're going to get is an integer so we i'm going to
get is an integer so we i'm going to write int
write int and
and title length
is equal to driver.gettitle.length and
and let's print it
let's print it so let's execute this
so let's execute this [Music]
[Music] so my chrome browser is launched
so my chrome browser is launched it's navigated
and let's see the length of the title of the page is seven
the page is seven now it is seven because
now it is seven because uh this is one two three four five six
uh this is one two three four five six seven
seven so the length of the title of the page
so the length of the title of the page is seven so now the next test case that
is seven so now the next test case that we have is to print the page source of
we have is to print the page source of the page
now for that i'm going to write driver dot
dot get page source
get page source i will store this in a string type of
i will store this in a string type of variable
string i will write
i will write ps is equal to
ps is equal to driver dot page source next let's print
driver dot page source next let's print it
it okay so now let's execute this
okay so now let's execute this so my chrome browser is launched
so my chrome browser is launched it's navigated and it's maximized
it's navigated and it's maximized and here you can see the page source
and here you can see the page source this is the entire page so that here you
this is the entire page so that here you can see is this
can see is this it prints the entire code of the page
it prints the entire code of the page okay so it's quite long
okay so it's quite long now we have to print the length of this
now we have to print the length of this right
so what i'm going to do is i'm going to write
write driver
driver dot
dot get paid source dot
get paid source dot length
length and i'm going to store it in the
and i'm going to store it in the integer type of variable
integer type of variable so i'll write in
so i'll write in its source
its source length is equal to
length is equal to driver.getpagesource.length
okay now let's print it
the length of the
length so this is the chrome browser
so this is the chrome browser now let's see here this is the length of
now let's see here this is the length of the pesos now we we won't sit and count
the pesos now we we won't sit and count but since it's too long
but since it's too long so this is the length of the page source
so this is the length of the page source now the next test case that we have is
now the next test case that we have is we have to click on the new tab right
we have to click on the new tab right so we use the click command over here
so we use the click command over here the click command is not a part of the
the click command is not a part of the browser
browser command it is a part of a web element
command it is a part of a web element command but since we have to
command but since we have to know the difference between the close
know the difference between the close and the quit so we are going to execute
and the quit so we are going to execute this command now this is the new tab
this command now this is the new tab command so i'll just inspect this
command so i'll just inspect this and go to selectors hub here i can see
and go to selectors hub here i can see the relative x path i'll just copy this
the relative x path i'll just copy this relative x path
relative x path i will write driver
i will write driver dot find element
dot find element by dot
by dot x path
x path and i will place my relative x path over
and i will place my relative x path over here
here and what i want to do is i want to click
and what i want to do is i want to click so i right click
and let's see [Music]
[Music] so my chrome browser is launched
so my chrome browser is launched it's navigated
it's navigated and it's maximized
and it's maximized and the new tab is clicked so here you
and the new tab is clicked so here you can see there is a new tab
can see there is a new tab okay so first we will see the close
okay so first we will see the close command
okay now if i write driver
now if i write driver dot
dot close
just look at it very closely so i'll just write
just write thread
dot sleep
sleep and i'll write 100 over here
and i'll write 100 over here so that you just get to know that how
so that you just get to know that how close method works
close method works okay it adds the exception towards
okay it adds the exception towards interrupted exception over here
interrupted exception over here and we're going to use a thread.sleep
and we're going to use a thread.sleep now thread.sleep is used in
now thread.sleep is used in multithreading if you know your
multithreading if you know your javascript concepts really well we you
javascript concepts really well we you we use stand.sleep it causes the
we use stand.sleep it causes the currently executing threat to sleep for
currently executing threat to sleep for some specified time so here i have
some specified time so here i have specified the time of 100 milliseconds
specified the time of 100 milliseconds so now
so now let's see the output
i want you to closely look at the how driver.close works
and the new tab is open and here you can see
the new tab is open and here you can see there was a parent tag over here
there was a parent tag over here the before tag okay let me increase the
the before tag okay let me increase the timing over here
so my chrome browser is launched it's navigated now this is my parent tab
navigated now this is my parent tab and this is my child tab now let's look
and this is my child tab now let's look at it
at it this tab will be close to close dot
this tab will be close to close dot driver command
driver command if you can see let me show it you again
this is my parent tag that is this browser windows is my parent tag
browser windows is my parent tag and this is my child tag now through
and this is my child tag now through driver.close the parent tag will be
driver.close the parent tag will be closed but my child is still open
closed but my child is still open okay
okay now i'll write
now i'll write now i will commend this and i will write
now i will commend this and i will write driver
driver now we'll use the quick method
so i'll just write driver
driver dot
dot quit
quit and i will
and i will write thread dot sleep
write thread dot sleep okay
okay now let's run this command
now let's run this command so my chrome browser is launched
so my chrome browser is launched it's navigated and this is my child tag
it's navigated and this is my child tag that's my parent tag and you will see
that's my parent tag and you will see driver dot
driver dot quit
quit closes both the tabs so uh this is the
closes both the tabs so uh this is the parent tag now here when we perform the
parent tag now here when we perform the driver dot close command and the driver
driver dot close command and the driver dot quit command there are two tabs okay
dot quit command there are two tabs okay uh this is the parent tab and here when
uh this is the parent tab and here when i click on new tab this is the child tab
i click on new tab this is the child tab okay
okay so when i
so when i write driver.close command it will just
write driver.close command it will just close the
close the parent tag it will not close the child
parent tag it will not close the child tab okay
tab okay whereas when i write driver.quit command
whereas when i write driver.quit command it will close the parent tab as well as
it will close the parent tab as well as the child tab so let's have a recap of
the child tab so let's have a recap of what we have done till now now the first
what we have done till now now the first test case was to open the chrome browser
test case was to open the chrome browser in which i have written the system.set
in which i have written the system.set property in which i have given the key
property in which i have given the key and the value the key is given that the
and the value the key is given that the webdriver.chrome.driver
webdriver.chrome.driver and the value is the chromedriver
and the value is the chromedriver executable file
executable file next we have to navigate to the url we
next we have to navigate to the url we can navigate to the url through two ways
can navigate to the url through two ways the first way we can do
the first way we can do driver.getcommand
driver.getcommand now this
now this java.getcommand
java.getcommand this opens a specified url in the
this opens a specified url in the browser
browser and this accepts a string as a parameter
and this accepts a string as a parameter here you can see this is a string as a
here you can see this is a string as a parameter and it returns nothing okay
parameter and it returns nothing okay so this is the first method where we can
so this is the first method where we can write the driver.getcommand the
write the driver.getcommand the getcommand is a part of the browser
getcommand is a part of the browser command
command and the second method that we can you is
and the second method that we can you is use is the we can assign the url to a
use is the we can assign the url to a string variable now here i have created
string variable now here i have created a string variable like i have create
a string variable like i have create string url and i have assigned the url
string url and i have assigned the url to the string variable and then i have
to the string variable and then i have written driver.get and i have written
written driver.get and i have written this variable in my get
this variable in my get the parameter that you are using is the
the parameter that you are using is the string okay so basically it accepts
string okay so basically it accepts string as a parameter and it returns
string as a parameter and it returns nothing this is about the get command
nothing this is about the get command next we have maximized the window for
next we have maximized the window for that we have used
driver.manage.window.maximize method okay
okay next we have to uh
next we have to uh find the url of the page what is the url
find the url of the page what is the url of the page
of the page this is the page and this is the url so
this is the page and this is the url so we have to find the url of this page
we have to find the url of this page so for that i have used the get current
so for that i have used the get current url method now this method fetches the
url method now this method fetches the string representing the current url
string representing the current url which is opened in the browser
which is opened in the browser okay and uh this accepts nothing as a
okay and uh this accepts nothing as a parameter there is no parameter given
parameter there is no parameter given over here but it returns a string value
over here but it returns a string value here you can see in the output here you
here you can see in the output here you can see in the output the url of the
can see in the output the url of the page so it returns the string value and
page so it returns the string value and it accepts nothing as a parameter
it accepts nothing as a parameter and what does the get current url method
and what does the get current url method does it does it fetches the string
does it does it fetches the string representing the current url which is
representing the current url which is open in the browser this page was opened
open in the browser this page was opened right so it was fetching this string
right so it was fetching this string this is the current url of the page
this is the current url of the page so for that we have given a string
so for that we have given a string variable that is a string url of the
variable that is a string url of the page and i have written driver dot get
page and i have written driver dot get current url and i've printed the url
current url and i've printed the url over here now to verify the url i have
over here now to verify the url i have used the if command in which i have
used the if command in which i have written the url of the page in which i
written the url of the page in which i am getting the
am getting the actual output and here i am matching the
actual output and here i am matching the actual and the expected output
actual and the expected output i'm using the equals method dot equals
i'm using the equals method dot equals now i'm writing over here the expected
now i'm writing over here the expected output that i want now if the expected
output that i want now if the expected and the actual output matches the output
and the actual output matches the output will be the url is verified and if not
will be the url is verified and if not the url is not verified now here it's
the url is not verified now here it's matched so it is written the url is
matched so it is written the url is verified so the next is that we have to
verified so the next is that we have to find the title of the page and we have
find the title of the page and we have to verify it
to verify it now to find the title of the page i will
now to find the title of the page i will be using the get title command now the
be using the get title command now the get title command is used to retrieve
get title command is used to retrieve the title of the web page
the title of the web page that the user is currently working on
that the user is currently working on now this is a page now when i inspect
now this is a page now when i inspect this here in the head tag you can see
this here in the head tag you can see the title
the title and here it is this is the title of the
and here it is this is the title of the page that is the tools qa this is the
page that is the tools qa this is the title of the page okay now to get this
title of the page okay now to get this title i have used the get title command
title i have used the get title command which retrieves the title of the web
which retrieves the title of the web page
page now it accepts nothing as a parameter
now it accepts nothing as a parameter can you see any parameters no right so
can you see any parameters no right so it accepts nothing as a parameter but it
it accepts nothing as a parameter but it returns a string value
returns a string value here you can see the value the title of
here you can see the value the title of the page is this this is the string
the page is this this is the string value that it is returning so to get the
value that it is returning so to get the title of the page i have written string
title of the page i have written string title i have created a string variable a
title i have created a string variable a title i have named as title and i've
title i have named as title and i've written driver.gettitle the title is
written driver.gettitle the title is stored in this string variable then i am
stored in this string variable then i am printing the string variable over here
printing the string variable over here to verify it i am using the if statement
to verify it i am using the if statement first i will write the actual output
first i will write the actual output that is the title
that is the title dot equals the expected output that i
dot equals the expected output that i want the expected output is our year
want the expected output is our year this is the expected output okay so here
this is the expected output okay so here the expected output is written when the
the expected output is written when the expected and the actual output is
expected and the actual output is matching the output will be the title is
matching the output will be the title is verified and if not the title is not
verified and if not the title is not verified like here you can see the title
verified like here you can see the title is verified now to print the length of
is verified now to print the length of the title i'm using the length command
the title i'm using the length command okay
okay what i'm going to do is i'm going to
what i'm going to do is i'm going to create a integer type of variable and
create a integer type of variable and i'll name it as integer length and i'll
i'll name it as integer length and i'll write driver dot get title dot length by
write driver dot get title dot length by writing length i am actually fetching
writing length i am actually fetching the total length of the title it returns
the total length of the title it returns the length of the string okay
the length of the string okay now uh to print it i'll write system dot
now uh to print it i'll write system dot out of println the length of the title
out of println the length of the title is and i'll write the variable that is
is and i'll write the variable that is the title length and here the output is
the title length and here the output is the length of the title is 7
the length of the title is 7 okay
okay next is the page source
next is the page source now basically page source is a command
now basically page source is a command it is a browser command
it is a browser command which uh returns the source code of the
which uh returns the source code of the page so this is the page and uh this is
page so this is the page and uh this is the entire source code of the page so it
the entire source code of the page so it will return this entire source code of
will return this entire source code of the page
the page so for this we'll use the get page
so for this we'll use the get page source
source and this get page source it accepts
and this get page source it accepts nothing as a parameter is there any
nothing as a parameter is there any parameter over here no right so it
parameter over here no right so it accepts nothing as a parameter but it
accepts nothing as a parameter but it returns a string value and the string
returns a string value and the string value this is the entire string value
value this is the entire string value that is given over here now to print the
that is given over here now to print the pace to source what i have written a
pace to source what i have written a string ps is equal to driver dot get
string ps is equal to driver dot get page source i have used the get paste
page source i have used the get paste source command and i will print this
source command and i will print this variable this uh string variable
variable this uh string variable then to find the length of the page
then to find the length of the page source what i have done i have used the
source what i have done i have used the length
length uh method i write
uh method i write driver.getpaidsource.length and i store
driver.getpaidsource.length and i store this length in the integer type of
this length in the integer type of variable named as ph length and i've
variable named as ph length and i've printed over here
printed over here so the total length is displayed over
so the total length is displayed over here
here this is the total length so these were
this is the total length so these were the commands the browser commands next
the commands the browser commands next we will learn about the click and the uh
we will learn about the click and the uh next we will learn about the close and
next we will learn about the close and the quit command the difference between
the quit command the difference between the close and the quit method okay
the close and the quit method okay for that we will click this new tab so
for that we will click this new tab so first what did i do is i clicked this uh
first what did i do is i clicked this uh new tab
new tab so for that i inspected this element and
so for that i inspected this element and i wrote the x path and i have performed
i wrote the x path and i have performed the click operation on this web element
the click operation on this web element next to differentiate between the close
next to differentiate between the close and the quit what i did is let me
and the quit what i did is let me execute this again first i have written
execute this again first i have written driver.close now then i have written
driver.close now then i have written thread.sleep which causes the currently
thread.sleep which causes the currently executing thread to sleep for specified
executing thread to sleep for specified time for example here i have written the
time for example here i have written the 5000 milliseconds okay now let me
5000 milliseconds okay now let me execute this command and see the
execute this command and see the difference again
difference again so my chrome browser is launched
so my chrome browser is launched it's maximized this is my parent and
it's maximized this is my parent and this is my child tab
this is my child tab my parent tab will be closed
my parent tab will be closed so this is close driver dot close which
so this is close driver dot close which means that the method terminates the
means that the method terminates the current browser window okay
current browser window okay whereas in quit it will terminate all
whereas in quit it will terminate all the browsers
the browsers so let's execute this
so let's execute this so my chrome browser is launched
so my chrome browser is launched it's navigated and here you can see this
it's navigated and here you can see this is the new tag
and through driver.quit both the tabs are closed
both the tabs are closed okay so uh this is the major difference
okay so uh this is the major difference between the close and the quit the close
between the close and the quit the close in both these commands they accept
in both these commands they accept nothing as a parameter
nothing as a parameter and it returns also nothing as a
and it returns also nothing as a parameter this simply closes the
parameter this simply closes the tabs and the windows
tabs and the windows so this is all about the browser
so this is all about the browser commands that we have studied till now
commands that we have studied till now we have studied about the get
we have studied about the get then we have studied about the get title
then we have studied about the get title the get current url
the get current url and we have studied about the get page
and we have studied about the get page source
then we have learned the difference between the
between the close and the quit command now let's
close and the quit command now let's understand
understand the difference
the difference so the driver.quick command closes all
so the driver.quick command closes all the browsers
the browsers whereas the closed method shall close
whereas the closed method shall close the browser which is in focus that was
the browser which is in focus that was the parent
the parent tab was in focus right so it closes that
tab was in focus right so it closes that browser which is in focus
browser which is in focus now the quick method closes all the
now the quick method closes all the active web driver instances whereas the
active web driver instances whereas the close method closes the
close method closes the active webdriver instances so this is
active webdriver instances so this is the difference between the quick and the
the difference between the quick and the close command
close command so in this tutorial we will understand
so in this tutorial we will understand what are the navigational commands what
what are the navigational commands what are the different types of navigation
are the different types of navigation commands with their syntax we will
commands with their syntax we will implement some test cases also we will
implement some test cases also we will understand the difference between the
understand the difference between the navigate.2 command and the get command
navigate.2 command and the get command in the previous tutorial i explained
in the previous tutorial i explained about the browser commands you can check
about the browser commands you can check out the tutorial
out the tutorial i'll give the link in the description
i'll give the link in the description box we will understand what is the
box we will understand what is the navigation commands today so first let
navigation commands today so first let us understand what is navigation
us understand what is navigation commands now the web driver provides
commands now the web driver provides some basic browser navigation commands
some basic browser navigation commands that allows the browser to move backward
that allows the browser to move backward forward or to refresh the browser see
forward or to refresh the browser see here you can see these buttons that is
here you can see these buttons that is the back and the forward and the refresh
the back and the forward and the refresh so we will be handling these buttons
so we will be handling these buttons through selenium webdriver like for
through selenium webdriver like for example suppose if i type a selenium web
example suppose if i type a selenium web driver i have navigated to this space
driver i have navigated to this space right now what if i want to go back so
right now what if i want to go back so i'll click on the back button
i'll click on the back button if i want to move forward i'll click on
if i want to move forward i'll click on the forward button and if i want to
the forward button and if i want to refresh the browser i will click on
refresh the browser i will click on refresh right
refresh right so these are the buttons that we will be
so these are the buttons that we will be inspecting today for that we have the
inspecting today for that we have the navigational commands
navigational commands now how do we find it's a navigation
now how do we find it's a navigation command we simply write driver
command we simply write driver dot
dot navigate dot and the commands that is
navigate dot and the commands that is highlighted over here are the
highlighted over here are the navigational commands okay also i have
navigational commands okay also i have prepared the sheet over here in which i
prepared the sheet over here in which i have written what are the navigational
have written what are the navigational commands their description their syntax
commands their description their syntax also what parameter it accepts and what
also what parameter it accepts and what it returns i will give the link in the
it returns i will give the link in the description box just by clicking it you
description box just by clicking it you can download the pdf
can download the pdf also i have attached the pdf in my drive
also i have attached the pdf in my drive so i will give the link of this drive as
so i will give the link of this drive as well so you can get the access of the
well so you can get the access of the navigation commands in pdf format also
navigation commands in pdf format also the test cases that we are going to
the test cases that we are going to implement today so moving on to the test
implement today so moving on to the test case today we are going to implement two
case today we are going to implement two test cases this is the first one
test cases this is the first one and this is the second one
and this is the second one so the first one says that first we have
so the first one says that first we have to launch the chrome browser then we
to launch the chrome browser then we have to open the amazon website
have to open the amazon website maximize the window
maximize the window and then we have to navigate to the ebay
and then we have to navigate to the ebay website through
website through driver.navigate.2 command
driver.navigate.2 command then we have to enter some value in the
then we have to enter some value in the search box we will refresh the page we
search box we will refresh the page we will navigate back then we will navigate
will navigate back then we will navigate forward and then we will close the
forward and then we will close the browser this is the first test case that
browser this is the first test case that we will implement today
we will implement today so open your intelligent idea ide now
so open your intelligent idea ide now under package com.selenium i have
under package com.selenium i have already created a java class i have
already created a java class i have named it as selenium tutorial 11
named it as selenium tutorial 11 so
so first is that we have to launch the
first is that we have to launch the chrome browser the test cases says that
chrome browser the test cases says that we have to launch the chrome browser for
we have to launch the chrome browser for that we have to write system.set
that we have to write system.set property in which the key is the
property in which the key is the webdriver.com.driver
webdriver.com.driver and the value is the executable file of
and the value is the executable file of the chrome driver
the chrome driver next i will write driver web driver
next i will write driver web driver driver is equal to new chrome driver so
driver is equal to new chrome driver so the next command is that
the next command is that we have to open the amazon site we will
we have to open the amazon site we will be using the driver.get command so i
be using the driver.get command so i will write driver
will write driver dot get
dot get and i will write my url over here that
and i will write my url over here that is the amazon website
i'll simply copy this and i'll paste it over here
over here okay
okay the next command is to maximize the
the next command is to maximize the window
window so i will write driver
so i will write driver dot manage
dot manage dot window dot maximize okay this will
dot window dot maximize okay this will maximize the
maximize the window
window the next the next test case is that we
the next the next test case is that we have to navigate to the ebay website
have to navigate to the ebay website so we will be using the
so we will be using the driver.navigate.2 method okay so i will
driver.navigate.2 method okay so i will write driver
write driver dot
navigate dot
dot 2.
2. so i'll write my url over here
this is the url i'll simply copy this
i'll simply copy this and i'll paste it over here
and i'll paste it over here now the driver.navigate.2
now the driver.navigate.2 method it loads a new page in the
method it loads a new page in the current browser so this will be loading
current browser so this will be loading a new page in the current browser the
a new page in the current browser the same browser in which it is loading
same browser in which it is loading amazon it will load the new page that is
amazon it will load the new page that is the ebay page in the current browser
the ebay page in the current browser and it will accept the parameter that is
and it will accept the parameter that is the string parameter is accepted over
the string parameter is accepted over here you can here you can see we have
here you can here you can see we have written the string parameter over here
written the string parameter over here and it will return nothing okay
and it will return nothing okay so let's execute this
it's navigated to amazon and then it's navigated to ebay
navigated to ebay i'll simply write
i'll simply write s out
okay so now let's execute so my chrome browser is launched it's
so my chrome browser is launched it's navigated to amazon
navigated to amazon [Music]
[Music] it's maximized and then it is navigated
it's maximized and then it is navigated to ebay through driver.navigate or to
to ebay through driver.navigate or to method okay and here you can see
method okay and here you can see the output that is it's opening the
the output that is it's opening the amazon page through driver.get and then
amazon page through driver.get and then it is navigated to ebay through
it is navigated to ebay through driver.navigate.2 method okay so so far
driver.navigate.2 method okay so so far first we will open the chrome browser
first we will open the chrome browser then we are opening the amazon page then
then we are opening the amazon page then we are maximizing the window then we are
we are maximizing the window then we are navigating to the ebay page through
navigating to the ebay page through driver.navigate.2 command okay
driver.navigate.2 command okay so the next test case is that i have to
so the next test case is that i have to enter some value this is the search box
enter some value this is the search box i have to enter some value in it so i'll
i have to enter some value in it so i'll just inspect i'll click i'll right click
just inspect i'll click i'll right click it and here here i can see there's
it and here here i can see there's selectors up so i'll just click on copy
selectors up so i'll just click on copy relative xpath
relative xpath i'll write driver
i'll write driver dot find element
dot find element by dot x path and i'll write my x path
by dot x path and i'll write my x path over here and since i want to send some
over here and since i want to send some commands so i'll write send keys and
commands so i'll write send keys and i'll write t-shirts
for men okay
okay so i have entered some value and then i
so i have entered some value and then i have to refresh it it's the same as here
have to refresh it it's the same as here you can see there is a refresh button
you can see there is a refresh button right so if i write t-shirt
for men and then i refresh it
and then i refresh it here you can see there is no text type
here you can see there is no text type that means it is refreshed so what i'll
that means it is refreshed so what i'll do i will write driver
do i will write driver dot
dot navigate
navigate dot refresh through this command my
dot refresh through this command my browser will be refreshed so i'll just
browser will be refreshed so i'll just write thread
dot sleep and i'll write some time over here
here i'll write refresh the browser
okay so next is that we have to navigate back
so next is that we have to navigate back to
to amazon
amazon so i will just write a driver
so i will just write a driver dot
dot navigate
navigate dot
dot back
back [Music]
[Music] okay and i'll give some time over here
okay and i'll give some time over here i'll just write thread
i'll just write thread dot
dot sleep and i'll give some time over here
sleep and i'll give some time over here which is
which is navigate it
navigate it back to
back to amazon
amazon okay so let's run this so my chrome
okay so let's run this so my chrome browser is launched
browser is launched it's navigated to amazon and it's
it's navigated to amazon and it's maximized
then it's navigated to ebay then t-shirts for men is sent
t-shirts for men is sent it's refreshed
it's refreshed and here you can see it's navigated back
and here you can see it's navigated back to amazon here it is opening the amazon
to amazon here it is opening the amazon page first we will open the amazon page
page first we will open the amazon page through driver.getmethod
through driver.getmethod then we navigated to ebay through
then we navigated to ebay through driver.navigate.2 method then we have
driver.navigate.2 method then we have refresh the browser and then the page is
refresh the browser and then the page is navigated back to amazon
navigated back to amazon now this
now this driver.navigate.back method is used to
driver.navigate.back method is used to return to the previous page in the
return to the previous page in the browser's history in our browser history
browser's history in our browser history the previous page was the amazon page
the previous page was the amazon page so it was returning the amazon page okay
so it was returning the amazon page okay and it accepts nothing as a parameter
and it accepts nothing as a parameter here there is no parameter and it
here there is no parameter and it accepts nothing as a parameter also it
accepts nothing as a parameter also it returns nothing okay
returns nothing okay similarly uh the refresh browse the
similarly uh the refresh browse the refresh command that that is the
refresh command that that is the driver.navigate.refresh method this acts
driver.navigate.refresh method this acts similar to the refresh button of the
similar to the refresh button of the browser like here you can see this is
browser like here you can see this is the refresh button of the browser this
the refresh button of the browser this acts similar to that
acts similar to that button and it accepts nothing as a
button and it accepts nothing as a parameter and it also returns nothing as
parameter and it also returns nothing as a parameter our next test case is that
a parameter our next test case is that we have to navigate forward
we have to navigate forward to ebay
to ebay so i will write driver
so i will write driver dot
dot navigate dot
navigate dot forward i will also write thread
forward i will also write thread dot sleep i will give some time over
dot sleep i will give some time over here
here then i want to print
then i want to print so let's execute this
so let's execute this so my chrome browser is launched
so my chrome browser is launched it's navigated to amazon
it's navigated to amazon it's maximized and then it's navigated
it's maximized and then it's navigated to ebay t-shirts for men is sent
to ebay t-shirts for men is sent it's refreshed
it's refreshed and it's navigated back to amazon
and it's navigated back to amazon then again it's navigated forward to
then again it's navigated forward to ebay
ebay next our next test case is that we have
next our next test case is that we have to close the browser so i will write
to close the browser so i will write driver dot close we'll not use the quit
driver dot close we'll not use the quit command because there is no window or
command because there is no window or any tab open see here all the operations
any tab open see here all the operations are performing in uh the current tab
are performing in uh the current tab only there are no other tabs that is
only there are no other tabs that is opening like if you're thinking like for
opening like if you're thinking like for amazon is one tab the ebay is the other
amazon is one tab the ebay is the other tab no it is opening in the current
tab no it is opening in the current browser and all the operations is
browser and all the operations is performed in the current browser only
performed in the current browser only that is it is navigating back or forward
that is it is navigating back or forward in the current browser
in the current browser so that's why we are writing
so that's why we are writing driver.close
driver.close so i'll execute this
so i'll execute this again
again [Music]
[Music] my chrome browser is launched
my chrome browser is launched it's navigated
it's navigated to amazon
to amazon it's maximized it's navigated to ebay
it's maximized it's navigated to ebay t-shirts for men is sent and it's
t-shirts for men is sent and it's refreshed
refreshed it's navigating back to amazon
it's navigating back to amazon and then again
and then again it's navigating forward to ebay and it's
it's navigating forward to ebay and it's closed so far first we navigated to ebay
closed so far first we navigated to ebay from amazon to ebay we navigated through
from amazon to ebay we navigated through driver.navigate.2 method now this method
driver.navigate.2 method now this method loads a new web page in the current
loads a new web page in the current browser window and it also accepts
browser window and it also accepts string as a parameter but it returns
string as a parameter but it returns nothing that is the
nothing that is the driver.navigate.2 method okay
driver.navigate.2 method okay next after uh navigating to ebay we
next after uh navigating to ebay we entered some text values we entered some
entered some text values we entered some values in the test search box and then
values in the test search box and then we refresh the browser the refresh
we refresh the browser the refresh method it does the same operation as
method it does the same operation as clicking on the refresh button on the
clicking on the refresh button on the browser when we click the refresh button
browser when we click the refresh button on the browser it does the same
on the browser it does the same operation
operation and it accepts nothing as a parameter
and it accepts nothing as a parameter also returns nothing next we were
also returns nothing next we were navigating back again to the amazon
navigating back again to the amazon website since we were on the ebay
website since we were on the ebay website and we were entering some value
website and we were entering some value and we refreshed the page then after
and we refreshed the page then after that we navigated back to the previous
that we navigated back to the previous page we use the
page we use the driver.navigate.back command which is
driver.navigate.back command which is used to return the previous page in the
used to return the previous page in the browser's history okay and it accepts
browser's history okay and it accepts nothing as a parameter it also returns
nothing as a parameter it also returns nothing else next after uh navigating to
nothing else next after uh navigating to back command we are in on the amazon web
back command we are in on the amazon web page on the amazon website we navigated
page on the amazon website we navigated forward to the ebay page that is the
forward to the ebay page that is the next page okay all the operations are
next page okay all the operations are performed on the current browser only
performed on the current browser only there is no other new tab or window that
there is no other new tab or window that is opened it is on the current window
is opened it is on the current window itself
itself so for the forward we use the driver dot
so for the forward we use the driver dot navigate dot forward method in which we
navigate dot forward method in which we move forward to the next space that is
move forward to the next space that is the ebay page and the forward command it
the ebay page and the forward command it accepts nothing as a parameter and it
accepts nothing as a parameter and it also returns nothing so this is all
also returns nothing so this is all about the first test case
about the first test case now let us execute the second test case
now let us execute the second test case so now let's execute the second test
so now let's execute the second test case
case just open your intelligent idea id and i
just open your intelligent idea id and i have already created a java class that
have already created a java class that is the selenium returns club java class
is the selenium returns club java class in the package com.selenium
in the package com.selenium and the first test case that we're
and the first test case that we're having is that you have to launch the
having is that you have to launch the chrome browser for which i have written
chrome browser for which i have written system that set property i have given
system that set property i have given the key as the webdriver.chrome
the key as the webdriver.chrome webdriver and the value is the chrome
webdriver and the value is the chrome driver executable file
driver executable file next i have written web driver driver is
next i have written web driver driver is equal to new chrome driver
equal to new chrome driver the next test case is that we have to
the next test case is that we have to navigate to the page and this is the
navigate to the page and this is the page that we will automate today so i
page that we will automate today so i will use driver
will use driver dot
dot navigate dot
navigate dot to command
to command and i will insert the ui level here
and i will insert the ui level here that is this is the url
that is this is the url now this driver.navigator2 command it
now this driver.navigator2 command it accepts string as a parameter and it
accepts string as a parameter and it returns nothing so
returns nothing so let's execute this
let's execute this so my chromebook is launched
so my chromebook is launched it's navigated to the webpage.com
okay so the next command is that we have to
so the next command is that we have to maximize the browser so i will just
maximize the browser so i will just write driver dot manage dot
write driver dot manage dot window dot maximize through this command
window dot maximize through this command my window will be maximized
my window will be maximized next test case is that i have to inspect
next test case is that i have to inspect this element that is i have to click on
this element that is i have to click on this button that is a get start button
this button that is a get start button so i'll just right click on it and i
so i'll just right click on it and i have this
have this selectors hub option over here i'll
selectors hub option over here i'll click on copy relative expat this tool
click on copy relative expat this tool is amazing that is the selectors up tool
is amazing that is the selectors up tool you can just simply right click on any
you can just simply right click on any element and you will get the option over
element and you will get the option over there like selectors up and you can copy
there like selectors up and you can copy your related x path over here
your related x path over here okay so
okay so i'll just write
i'll just write driver dot
driver dot sign element
sign element by dot
by dot x path and i will paste my relative x
x path and i will paste my relative x path over here
path over here and since i want to click on this button
and since i want to click on this button so i will click on clip
so i will click on clip method
method so let's execute this
so let's execute this so my chromebook is launched it's
so my chromebook is launched it's navigated to the wordpress website it's
navigated to the wordpress website it's maximize and here it's the button is
maximize and here it's the button is click that is the get start button is
click that is the get start button is click develop
click develop okay
okay so now next is that i have to navigate
so now next is that i have to navigate back to the home page so i'll just write
back to the home page so i'll just write driver dot navigate
driver dot navigate dot
dot back i'll also give
back i'll also give some time over here so i'll just write
some time over here so i'll just write thread.sleep
thread.sleep now let's execute
now let's execute so my chromebook is launched
so my chromebook is launched it's navigated to wordpress
it's navigated to wordpress let's
let's maximize the button is clicked
and it's navigating back to the home page
page okay
okay so the next command is
so the next command is that we have to again go back to
that we have to again go back to the get start page
the get start page so i'll just write driver
so i'll just write driver dot navigate dot forward
dot navigate dot forward and i'll give some time
and i'll give some time so i'll write a
so i'll write a thread dot sleep
thread dot sleep and i'll specify some time over here
and i'll specify some time over here that is 5000
that is 5000 and then let's run this command
and then let's run this command [Music]
[Music] so my chromebook is launched
so my chromebook is launched it's navigated to the wordpress website
it's navigated to the wordpress website it's maximized
it's maximized [Music]
[Music] and the button is clicked
and the button is clicked [Music]
[Music] we're navigating back to the home page
we are navigating forward to the get start page
okay next is that we have to perform the refresh operation
refresh operation so i'll write driver dot navigate
so i'll write driver dot navigate dot
dot refresh
refresh and then we have to close the browser
so i'll write driver dot close we specify some time over
specify some time over so i'll write thread dot sleep
so i'll write thread dot sleep and here also i'll write
and here also i'll write thread dot
thread dot sleep
sleep now let's execute this
now let's execute this so my chrome browser is launched
so my chrome browser is launched [Music]
[Music] it's navigating the wordpress website
it's navigating the wordpress website it's maximized
it's maximized [Music]
[Music] okay so that get start button is clicked
okay so that get start button is clicked we're navigating back to the home page
we're navigating back to the home page [Music]
navigating forward to the get start page [Music]
refresh [Music]
and the browser is closed so this is all about the navigation commands in which
about the navigation commands in which we have the navigate to method which
we have the navigate to method which loads a new web page in the current
loads a new web page in the current browser window and it accepts string as
browser window and it accepts string as a parameter returns nothing next we have
a parameter returns nothing next we have the refresh command which works same as
the refresh command which works same as the refresh button of any browser this
the refresh button of any browser this is the refresh button of the browser and
is the refresh button of the browser and the syntax is that the
the syntax is that the driver.navigate.refresh
driver.navigate.refresh and it accepts nothing as a parameter
and it accepts nothing as a parameter and it returns nothing next is the back
and it returns nothing next is the back command used to return the previous page
command used to return the previous page in the browser's history the syntax is
in the browser's history the syntax is that the driver dot navigate the back
that the driver dot navigate the back command and it accepts nothing as a
command and it accepts nothing as a parameter also returns nothing next we
parameter also returns nothing next we have the forward command we will move to
have the forward command we will move to the forward page through driver dot
the forward page through driver dot navigate the forward command so these
navigate the forward command so these are the navigation commands that we have
are the navigation commands that we have studied today also we have executed two
studied today also we have executed two test cases out of it
test cases out of it next let us know the difference between
next let us know the difference between the
the driver.navigator2 and the driver.jet
driver.navigator2 and the driver.jet since when we write driver.navigator2 uh
since when we write driver.navigator2 uh and we write the url over here it
and we write the url over here it performs the same operation also when we
performs the same operation also when we write driver.get it performs the same
write driver.get it performs the same operation but yet they both are
operation but yet they both are different okay now the
different okay now the driver.navigator2 command it is
driver.navigator2 command it is responsible for redirecting the page and
responsible for redirecting the page and then returning immediately like through
then returning immediately like through driver.navigate we can navigate to
driver.navigate we can navigate to forward we can now draw we can write
forward we can now draw we can write driver.navigate.back then we can write
driver.navigate.back then we can write driver.navigate.refresh but is there any
driver.navigate.refresh but is there any command like driver.get.forward
command like driver.get.forward no right there is no command as such so
no right there is no command as such so driver.get is responsible for loading
driver.get is responsible for loading the page and it waits until the page has
the page and it waits until the page has finished loading that's it that is what
finished loading that's it that is what driver.get is responsible for
driver.get is responsible for whereas driver.navigate is responsible
whereas driver.navigate is responsible for redirecting the page we can perform
for redirecting the page we can perform the navigation
the navigation uh operations like we can move forward
uh operations like we can move forward we can move backwards and then we can
we can move backwards and then we can refresh the browser so this is what is
refresh the browser so this is what is driver.navigate responsible for
driver.navigate responsible for also the driver.navigator2 command it
also the driver.navigator2 command it tracks the browser history and can
tracks the browser history and can perform back and forth in the browser
perform back and forth in the browser like we have seen in the test cases we
like we have seen in the test cases we were performing the back operation and
were performing the back operation and the forward operation so it tracks the
the forward operation so it tracks the browser history whereas the driver.get
browser history whereas the driver.get does not track any of the history of a
does not track any of the history of a browser
browser like through
like through driver.get.forward there's no such
driver.get.forward there's no such command so
command so it is not tracking any of the history of
it is not tracking any of the history of the browser so these are the major
the browser so these are the major difference between the driver.net
difference between the driver.net driver.navigate command and the
driver.navigate command and the driver.get command so this is all for
driver.get command so this is all for today in the next tutorial we will
today in the next tutorial we will understand about the web element
understand about the web element commands i have also provided this sheet
commands i have also provided this sheet in which i have written the commands
in which i have written the commands description syntax and what parameter it
description syntax and what parameter it accepts and returns i will provide the
accepts and returns i will provide the link in the description box you can
link in the description box you can directly download the pdf format also
directly download the pdf format also the link to the drive also i will
the link to the drive also i will provide in the description box so it
provide in the description box so it will be very useful for you to revise
will be very useful for you to revise during your interviews so this is all
during your interviews so this is all for today so in this tutorial we will
for today so in this tutorial we will understand some of the web element
understand some of the web element commands we will understand the
commands we will understand the different types of web element commands
different types of web element commands with their syntax
with their syntax also we will implement these commands
also we will implement these commands then we will understand the difference
then we will understand the difference between find elements and find element
between find elements and find element also we will understand the difference
also we will understand the difference between the is displayed is enabled and
between the is displayed is enabled and is selected method and click and submit
is selected method and click and submit method
method so let's get started
so let's get started first we need to understand what are web
first we need to understand what are web elements command to understand what is
elements command to understand what is web element command we need to
web element command we need to understand what is web element
understand what is web element anything that is present on the web page
anything that is present on the web page is called as a web element for example
is called as a web element for example the text boxes the buttons the drop down
the text boxes the buttons the drop down menu the radio buttons etc everything is
menu the radio buttons etc everything is called web element to interact these web
called web element to interact these web elements we have the different types of
elements we have the different types of locators like the id name class the
locators like the id name class the xpath i have explained that in the
xpath i have explained that in the previous tutorial the web element
previous tutorial the web element commands are the list of actions that
commands are the list of actions that can be performed on various web elements
can be performed on various web elements these are called as the web element
these are called as the web element commands now here you can see these list
commands now here you can see these list of web element commands that is the
of web element commands that is the click clear
click clear the find element the find elements the
the find element the find elements the get attribute the get css value also i
get attribute the get css value also i have prepared a document
have prepared a document in this document i have mentioned the
in this document i have mentioned the commands the description the syntax and
commands the description the syntax and what parameter it accepts and what it
what parameter it accepts and what it returns also you can get this document
returns also you can get this document in the pdf format i have attached it to
in the pdf format i have attached it to the
the drive
drive i will give this link in the description
i will give this link in the description box also i will give the direct link to
box also i will give the direct link to download as a pdf
download as a pdf so these are the commands like the clear
so these are the commands like the clear click the submit the send keys and the
click the submit the send keys and the element visibility methods and also
element visibility methods and also these get text get tag name the get css
these get text get tag name the get css get attribute get size and get location
get attribute get size and get location so these are the different web element
so these are the different web element commands and we will be understanding
commands and we will be understanding these commands today through set of test
these commands today through set of test cases
cases this is a test case that we're going to
this is a test case that we're going to implement today
implement today and this is the website that we're going
and this is the website that we're going to automate today
to automate today so
so first
first open your intelligent idea id
so i have created this java class selenium tutorial 13 under package
selenium tutorial 13 under package comrade selenium
comrade selenium and the first test case says that i have
and the first test case says that i have to launch the chrome browser for that i
to launch the chrome browser for that i have written system.set property in
have written system.set property in which i have given the key that is the
which i have given the key that is the webdriver.chrome.driver
webdriver.chrome.driver and the value is the executable file of
and the value is the executable file of the chrome driver
the chrome driver next is the webdriver driver is equal to
next is the webdriver driver is equal to new chrome driver so these two commands
new chrome driver so these two commands will launch the chrome browser
will launch the chrome browser our next test case is that we have to
our next test case is that we have to open the url so i'll be using driver.get
i'll insert the url that i want to navigate to this is the url
navigate to this is the url so i'll copy this
so i'll copy this paste it over here
and then i will maximize the page for that i will write driver
for that i will write driver dot
dot manage
manage dot
dot window
window dot
dot maximize
so my chrome browser is launched it's navigated
it's navigated and it's maximized so my next test case
and it's maximized so my next test case is that i have to enter the username and
is that i have to enter the username and password
password so this is username and this is the
so this is username and this is the password i will inspect this element
password i will inspect this element i'll simply click on inspect
i'll simply click on inspect and here you can see we have the id name
and here you can see we have the id name attribute so i'll use the id attribute
attribute so i'll use the id attribute i'll write
i'll write driver dot find element
driver dot find element by dot id
by dot id and i will mention the id over here
and here i'll be using the send keys command
command now the send keys command accepts the
now the send keys command accepts the character sequence as a parameter and it
character sequence as a parameter and it returns nothing
returns nothing so the character sequence that i want to
so the character sequence that i want to send over here is the username
send over here is the username the username is given here so i'll
the username is given here so i'll simply just copy this
i will paste it over here and this is the
and this is the character that i want to send to
character that i want to send to username
username next i'll write driver
next i'll write driver dot find element
dot find element by dot id
the next element is the password so i'll inspect this
inspect this the id
the id i'll copy it over here
i'll copy it over here and the operation that i want to perform
and the operation that i want to perform over here is that i want to send some
over here is that i want to send some character sequence to the password field
character sequence to the password field so here i will write the password
so here i will write the password the password is given over here
the password is given over here so i'll simply copy this
so i'll simply copy this and paste it over here
and paste it over here so this is the first web element command
so this is the first web element command that we learnt is the send key so here
that we learnt is the send key so here you can see we have send keys now this
you can see we have send keys now this send keys stimulates the typing into an
send keys stimulates the typing into an element which may sets its value this is
element which may sets its value this is the syntax
the syntax this is the parameter that is the
this is the parameter that is the character sequence it accepts as a
character sequence it accepts as a parameter and it returns nothing
parameter and it returns nothing so let's execute this
so my chrome browser is launched it's navigated
navigated it's maximized and the username and the
it's maximized and the username and the password is
password is send
send so our next test case says that we have
so our next test case says that we have to clear the username and the password
to clear the username and the password that we have entered for that we'll use
that we have entered for that we'll use the clear command okay
the clear command okay so i will simply write driver
so i will simply write driver dot
dot find element
find element by dot id
by dot id dot
dot i'll use the clear command
it accepts nothing as a parameter it also returns nothing
also returns nothing next i want to clear the password so
next i want to clear the password so i'll write driver dot fine element
i'll write driver dot fine element by dot id
dot clear command
clear command now let's execute this
so my chrome browser is launched it's navigated
it's maximized and my username password is entered
so here you can see the username is cleared
cleared and the password is also cleared
and the password is also cleared okay
okay so this is the next
so this is the next web element command that we have learned
web element command that we have learned so this is the next uh web element
so this is the next uh web element command that we have learnt is the clear
command that we have learnt is the clear command this will clear the value this
command this will clear the value this is the syntax and it accepts nothing as
is the syntax and it accepts nothing as a parameter also returns nothing
a parameter also returns nothing okay
okay so our next test case says that we have
so our next test case says that we have to submit the login button so here comes
to submit the login button so here comes the difference between the click command
the difference between the click command and the summit command these two
and the summit command these two commands for that i have an example
commands for that i have an example let's understand that with the help of
let's understand that with the help of the example first and then
the example first and then we'll perform the test case
we'll perform the test case to understand the difference between the
to understand the difference between the summit and the click this is the page
summit and the click this is the page that i have made there are two divisions
that i have made there are two divisions present over here one is the outside
present over here one is the outside form tag and the second division is the
form tag and the second division is the inside form type in the outside form tag
inside form type in the outside form tag there are two buttons as well as in this
there are two buttons as well as in this inside form tag there are two buttons
inside form tag there are two buttons that is the submit button and the button
that is the submit button and the button the first one is of type submit here you
the first one is of type submit here you can see this is input type submit and
can see this is input type submit and this is of
this is of type button okay
type button okay so when i click on this this shows that
so when i click on this this shows that the submit button
the submit button outside the form tag and this is a
outside the form tag and this is a button outside the form text similarly
button outside the form text similarly when i click on this this shows that
when i click on this this shows that this is a button inside a form tag
this is a button inside a form tag and this is a button inside the form tag
and this is a button inside the form tag so now i created this page just to
so now i created this page just to understand the difference between the
understand the difference between the click and the submit method okay
click and the submit method okay so uh i have already created a java
so uh i have already created a java class i have named it as difference
class i have named it as difference between submit and click i have opened
between submit and click i have opened the chrome browser i navigated to this
the chrome browser i navigated to this page i maximize it the first operation
page i maximize it the first operation that we're going to perform is the click
that we're going to perform is the click operation and then we will perform the
operation and then we will perform the summit operation and then we will see
summit operation and then we will see the difference between the two
the difference between the two so the first operation is the click
so the first operation is the click operation and i inspected the
operation and i inspected the outside form tag division first okay in
outside form tag division first okay in which i click the submit button and the
which i click the submit button and the button
button so let's see let's execute this
so let's see let's execute this so my chrome browser is launched
submit button is clicked then i navigated back
then i navigated back then the button is clicked
and it is navigated so my click method works for a submit button and the
method works for a submit button and the button which is outside the form tag
button which is outside the form tag now let's see whether it works for the
now let's see whether it works for the inside the form tag or not
so i have written this code for the inside the form tag
inside the form tag in which i have inspected the uh
in which i have inspected the uh submit button and the button through id
submit button and the button through id locator and i have also written
locator and i have also written driver.navigate.back command just to
driver.navigate.back command just to navigate back to the page
navigate back to the page and i have also written thread dot sleep
and i have also written thread dot sleep uh which shows the time so that it slows
uh which shows the time so that it slows down the execution and we get to know
down the execution and we get to know what is actually happening
what is actually happening so let's execute this
here my chrome browser is launched it's navigated to this page it's
it's navigated to this page it's maximized
so this is the button inside the form tag the submit button is clicked
tag the submit button is clicked it's navigated back
so the button is also clicked and it's navigated back
and it's navigated back so here we can conclude that the click
so here we can conclude that the click method is having no restrictions
method is having no restrictions that is you can use click method to
that is you can use click method to click on any button
click on any button if it is of element of type button or of
if it is of element of type button or of type submit the click will work for both
type submit the click will work for both okay whether it is outside the form tag
okay whether it is outside the form tag or whether it is inside the form tag now
or whether it is inside the form tag now let's see the summit
to understand the submit method this is the first division that
method this is the first division that we are having the outside form tag so we
we are having the outside form tag so we will inspect this element first and
will inspect this element first and let's see what the output is so i have
let's see what the output is so i have written driver.find element and by dot
written driver.find element and by dot id i have specified the id and the
id i have specified the id and the submit method and then i have written
submit method and then i have written thread dot sleep to understand the
thread dot sleep to understand the execution
execution so now let's execute this
so now let's execute this so my chrome browser is launched
so my chrome browser is launched it's navigated
it's navigated it's maximized
and here you can see there is an exception over here
there is an exception of javascript execution the javascript error error
execution the javascript error error unable to find moving document okay so
unable to find moving document okay so this shows that
this shows that the submit button will not work for a
the submit button will not work for a summit type of element outside the form
summit type of element outside the form tag now let's see if it works for the
tag now let's see if it works for the button type of element or not
button type of element or not so i have written over your driver.find
so i have written over your driver.find element by dot id and this is the id and
element by dot id and this is the id and i will use the
i will use the submit method
submit method over here and i have given thread.sleep
over here and i have given thread.sleep just to see its execution so that you
just to see its execution so that you can pause for some time
can pause for some time and let's execute this
my chrome browser is launched it's navigated it's maximized
okay so again here you can see we have a error
error which says that is unable to find owing
which says that is unable to find owing document so this means that the summary
document so this means that the summary function is not applicable for the
function is not applicable for the buttons that is outside the form tag
buttons that is outside the form tag okay now let's see
okay now let's see is it applicable for buttons that is
is it applicable for buttons that is inside the form tag
inside the form tag so here i have written driver dot find
so here i have written driver dot find element by dot id and the id i have
element by dot id and the id i have specified over here and the submit
specified over here and the submit command and i've also written
command and i've also written driver.navigate.back
driver.navigate.back command now let's see whether
command now let's see whether it is executing or not or whether it
it is executing or not or whether it shows an error
so my chromebook has launched it's navigated
and here it is this is a button inside a
here it is this is a button inside a form tag and then it is navigated back
form tag and then it is navigated back okay
okay so our submit function is working inside
so our submit function is working inside the form tag for the submit button but
the form tag for the submit button but what about the
what about the element of type button
element of type button so i have written this driver.find
so i have written this driver.find element by dot id
element by dot id and this is the id that is that i have
and this is the id that is that i have given over here and the summit command
given over here and the summit command and also thread dot sleeve so that we
and also thread dot sleeve so that we can
can see the execution
see the execution so my chrome browser is launched it's
so my chrome browser is launched it's navigated
navigated and this is the button inside the form
and this is the button inside the form tag
tag so here you can see we had the division
so here you can see we had the division that is the inside the form tag division
that is the inside the form tag division in which uh i had two buttons that the
in which uh i had two buttons that the submit button and the button right so i
submit button and the button right so i could automate the submit button as well
could automate the submit button as well as this button also so the summit
as this button also so the summit function is applicable only for buttons
function is applicable only for buttons that are inside the form tag so this
that are inside the form tag so this means that there are some restrictions
means that there are some restrictions for the submit method and there is no
for the submit method and there is no restrictions for the click method
restrictions for the click method so let's see the difference between the
so let's see the difference between the two
two so this is the difference
so this is the difference for the click method you can use the
for the click method you can use the click method to click on any button
click method to click on any button whereas the summit function is
whereas the summit function is applicable only for buttons that is
applicable only for buttons that is inside the form tag
inside the form tag there is no restrictions for click
there is no restrictions for click button but there are some restrictions
button but there are some restrictions for submit button that is it is only
for submit button that is it is only applicable if the button is inside the
applicable if the button is inside the form tag
form tag now this means that
now this means that when there is no restriction for click
when there is no restriction for click buttons that this means that the element
buttons that this means that the element type is button or it is of type summit
type is button or it is of type summit the click method will work for both
the click method will work for both but whereas the element type of submit
but whereas the element type of submit or button it should be inside the form
or button it should be inside the form tag then only the summit method will
tag then only the summit method will work
work okay now if the button is inside the
okay now if the button is inside the form tag or the button is outside the
form tag or the button is outside the form type the click will work but if the
form type the click will work but if the button is outside the form tag that
button is outside the form tag that means the summit will not work as we
means the summit will not work as we have seen in the example before
have seen in the example before so now moving on to the next test case
so now moving on to the next test case that is the submit our login button is
that is the submit our login button is to submit our login form right so your
to submit our login form right so your let's inspect this element
now this element is of type submit and it is under the form tag so we can use
it is under the form tag so we can use the summit command
the summit command so i'll simply write driver
so i'll simply write driver dot find element
dot find element by dot
x path and
and i will paste it over here okay so here i have written driver
okay so here i have written driver driver.find element and this is the
driver.find element and this is the expert that is present and the operation
expert that is present and the operation that i want to perform is i want to
that i want to perform is i want to submit it
submit it so now let's execute this
so now let's execute this my chrome browser is launched
my chrome browser is launched it's navigated
it's navigated my username is entered password is
my username is entered password is entered username is cleared password is
entered username is cleared password is cleared
cleared and here you can see the login button is
and here you can see the login button is clicked and
clicked and here the warning is given the username
here the warning is given the username cannot be empty so our next test case is
cannot be empty so our next test case is the get text
the get text now this method will fetch the visible
now this method will fetch the visible uh inner text of the element
uh inner text of the element and it accepts nothing as a parameter
and it accepts nothing as a parameter but it returns a string value for
but it returns a string value for example
example suppose this element here you can see
suppose this element here you can see this link
this link if i inspect this here you can see we
if i inspect this here you can see we have the forget your password text
have the forget your password text written over here so get text fill
written over here so get text fill method get text method will retrieve
method get text method will retrieve this
this forget your password okay it will fetch
forget your password okay it will fetch the inner visible text that is present
the inner visible text that is present over here there is a text present right
over here there is a text present right forget your password so it will print
forget your password so it will print forget your password through get text
forget your password through get text method
method so what i'll do is i'll write driver
so what i'll do is i'll write driver dot find element
dot find element by dot link text
by dot link text and the text that is present over here
and the text that is present over here is this so i'll simply copy this
and i'll write get
get text
and i will print it let me execute this
let me execute this my chrome browse is launched
my chrome browse is launched it's navigated
it's navigated it's executed
username password is entered the username is cleared the password is
the username is cleared the password is cleared
the submit button is clicked and here you can see we have the text
and here you can see we have the text let's forget your password
let's forget your password okay
okay then the next test case says that get
then the next test case says that get location
location now the get location method this method
now the get location method this method locates the location of the element on
locates the location of the element on the page and it accepts nothing as a
the page and it accepts nothing as a parameter but it returns a point object
parameter but it returns a point object now here i will write driver
now here i will write driver dot find element by dot id
dot find element by dot id i will store this in a web element
i will store this in a web element type of variable
so i'll use the point class over here and then i will write element dot get
and then i will write element dot get location
location next i will print it
next i will print it plus point dot
plus point dot x
x y coordinates
y coordinates point dot y
point dot y so let me execute this
so let me execute this my chrome browser is launched it's
my chrome browser is launched it's navigated
navigated it's maximized
it's maximized my username and password is enter
my username and password is enter my username is cleared my password is
my username is cleared my password is cleared
cleared so my login button is clicked
so my login button is clicked and here you can see the text is
and here you can see the text is forget your password x coordinates and
forget your password x coordinates and the y coordinates
so through
through get location we can
get location we can locate the location of the element on
locate the location of the element on the page on this page i was locating
the page on this page i was locating this element that is the user name
this element that is the user name that's what i found through
that's what i found through get location method
get location method next
next test case says that you have to find the
test case says that you have to find the size that is the get
size so here the get size method fetches the
so here the get size method fetches the width and the height of the element
width and the height of the element now over here i will inspect this
now over here i will inspect this element only i will i want to know the
element only i will i want to know the width and the height of this element for
width and the height of this element for that i will be using the get size method
that i will be using the get size method now remember the get size method is
now remember the get size method is different and the size method is
different and the size method is different they both are different okay
different they both are different okay now
now this get size method it accepts nothing
this get size method it accepts nothing as a parameter but it returns the
as a parameter but it returns the dimension object so similarly i'll write
dimension object so similarly i'll write the code for this
the code for this i'll write driver dot find element
i'll write driver dot find element by dot id
and i will store this in a web element type of variable
type of variable i will name it as element 1
i will name it as element 1 is equal to driver.fine element by dot
is equal to driver.fine element by dot ire
ire okay next i will write dimensions
dimension is equal to element
element 1 dot
1 dot get
get size next i will write s out and i'll
size next i will write s out and i'll write
write height is
height is and i'll write dimension that is the dim
and i'll write dimension that is the dim dot height
dot height and i will write
and i will write him dot
him dot so let's execute this
so let's execute this so my chrome browser is launched it's
so my chrome browser is launched it's navigated
navigated it's maximized and my username password
it's maximized and my username password is entered
is entered my username is cleared password is
my username is cleared password is cleared
cleared the login button is clicked
the login button is clicked and here you can see the height and the
and here you can see the height and the width that is given
width that is given of
of this element that is the username
this element that is the username element
element so the next test case says that we have
so the next test case says that we have to find the get tag name now the get tag
to find the get tag name now the get tag name method it gets the tag name of the
name method it gets the tag name of the element for example suppose
element for example suppose if i inspect this element
if i inspect this element this is the element that i'm inspecting
this is the element that i'm inspecting element that is there so the tag name is
element that is there so the tag name is input so it will retrieve the input
input so it will retrieve the input this is the tag name that is of this
this is the tag name that is of this element right so the tag name of this
element right so the tag name of this element is redrive that is the input so
element is redrive that is the input so let's see i'll simply write driver
dot find element by dot id
by dot id and i will place the id over here
i'll write get tag name
tag name and i'll print this value
and i'll print this value so i'll store it in a string type of
so i'll store it in a string type of variable because it returns string
let's execute this so my chromebook is launched it's
so my chromebook is launched it's navigated the username password is
navigated the username password is entered
entered the username is cleared the password is
the username is cleared the password is cleared
cleared and my login button is clicked
and my login button is clicked and here you can see we have the tag
and here you can see we have the tag name that is the input
name that is the input so the next test case is that we have to
so the next test case is that we have to print the number of links present on the
print the number of links present on the page now i have given this test case to
page now i have given this test case to understand the difference between the
understand the difference between the fine element and the find elements
fine element and the find elements so what i'll do is i'll write driver dot
so what i'll do is i'll write driver dot find elements
find elements by dot
by dot tag name i'll use the tag name and to
tag name i'll use the tag name and to find the links on the page the tag that
find the links on the page the tag that we use is the
we use is the a tag right the anchor tag so i'll write
a tag right the anchor tag so i'll write a
and i will store this in a list i'll use the web element
i'll use the web element because i have to inspect the web
because i have to inspect the web element over here
element over here the different types of web element that
the different types of web element that is i want to know the list of
is i want to know the list of links that is present over here right so
links that is present over here right so i'm using the list and the element that
i'm using the list and the element that i want to inspect is the web element
i want to inspect is the web element and i will give a variable name
and i will give a variable name i'll name it as links is equal to
i'll name it as links is equal to driver.find elements by dot tag name
driver.find elements by dot tag name and then i will print this
and then i will print this that is i'll print the number of
that is i'll print the number of links that is present over here to print
links that is present over here to print the number of links that
the number of links that that is present over here i'll use the
that is present over here i'll use the size method
size method remember the get size method is
remember the get size method is different whereas the size method is
different whereas the size method is different the size
different the size method retrieves the number of elements
method retrieves the number of elements in the list whereas over here the get
in the list whereas over here the get size method this method that you see
size method this method that you see this is the get size method this shows
this is the get size method this shows the width and the height of the element
the width and the height of the element my chrome browser is launched it's
my chrome browser is launched it's navigated
navigated it's maximized
it's maximized the username and the password is entered
the username and the password is entered the username is cleared the password is
the username is cleared the password is clear
clear and the login button is clicked okay
and the login button is clicked okay here you can see we have the
here you can see we have the number that is present over here that is
number that is present over here that is six there are six
six there are six links present on this page
links present on this page okay
okay now here you can see we have used the
now here you can see we have used the find elements method over here okay now
find elements method over here okay now the main difference between the fine
the main difference between the fine element and the fine elements is that
element and the fine elements is that the fine element returns the first
the fine element returns the first matching web element if the multiple web
matching web element if the multiple web elements are discovered by the locator
elements are discovered by the locator okay and here the find elements returns
okay and here the find elements returns the list of multiple matching web
the list of multiple matching web elements
elements in find element it will throw no such
in find element it will throw no such element exception if the element is not
element exception if the element is not found whereas in find elements it
found whereas in find elements it returns the empty list it will return
returns the empty list it will return the empty list if no element is matching
the empty list if no element is matching over here
over here find element detects a unique web
find element detects a unique web element whereas the fine elements it
element whereas the fine elements it returns the collection of matching
returns the collection of matching elements we have seen the example also
elements we have seen the example also over here
over here so this is the main difference between
so this is the main difference between the fine element and the find elements
the fine element and the find elements now the next test case is that
now the next test case is that we have to check if the login button is
we have to check if the login button is displayed or not now here we are using
displayed or not now here we are using the
the element visibility methods okay
element visibility methods okay we have three types of element
we have three types of element visibility method one is the is
visibility method one is the is displayed one is is enabled and one is
displayed one is is enabled and one is is selected
is selected now the is selected method is mostly
now the is selected method is mostly used for radio buttons and check boxes
used for radio buttons and check boxes whereas the is displayed in is enable
whereas the is displayed in is enable method is used for all types of web
method is used for all types of web elements that is present on the web page
elements that is present on the web page all these methods it accepts nothing as
all these methods it accepts nothing as a parameter but they return boolean
a parameter but they return boolean values that is the true and the false
values that is the true and the false the is displayed method this method
the is displayed method this method determines if an element is currently
determines if an element is currently displayed or not for example if the test
displayed or not for example if the test case is that check if the login button
case is that check if the login button is displayed that is this login button
is displayed that is this login button it is displayed on this page right on
it is displayed on this page right on this web page so when i write
this web page so when i write driver dot file element dot
driver dot file element dot id and if i located by id and when i
id and if i located by id and when i write is displayed it will show true
write is displayed it will show true because this element is displayed on the
because this element is displayed on the web page now let's see if i write
web page now let's see if i write now if i write is displayed
and if i save it in a boolean type of a variable because it returns true or
variable because it returns true or false so if i write
false so if i write boolean 1
boolean 1 is equal to
is equal to driver.find element x bar then this is
driver.find element x bar then this is displayed and i will print it over here
displayed and i will print it over here so here the output will be true
so here the output will be true because the element is displayed on the
because the element is displayed on the web page right
web page right so the output will be true so let's
so the output will be true so let's execute
execute this my chrome browser is launched it's
this my chrome browser is launched it's navigated my username and password is
navigated my username and password is entered
entered my username is erased and the password
my username is erased and the password is also clear
is also clear and the login is
and the login is clicked
clicked and here you can see we have the value
and here you can see we have the value that is true
that is true why it is true because this login button
why it is true because this login button is displayed on the web page
is displayed on the web page so next test case says that we have to
so next test case says that we have to check if the login button is enabled or
check if the login button is enabled or not
not now here i have written a boolean
now here i have written a boolean variable that i have given is the bool2
variable that i have given is the bool2 and i have written driver.find element
and i have written driver.find element and the xpath and i have used the is
and the xpath and i have used the is enabled method now this method the minus
enabled method now this method the minus of the element is currently enabled or
of the element is currently enabled or not here you can see this uh element is
not here you can see this uh element is enabled right if i click on this i can
enabled right if i click on this i can see over here it is enabled
see over here it is enabled so
so let's see the output will be true
let's see the output will be true because this element is enabled
because this element is enabled my chrome browser is
my chrome browser is launched it's navigated
launched it's navigated it's maximized
it's maximized and the username and the password is
and the username and the password is entered the username is cleared
entered the username is cleared the password is cleared
the password is cleared [Music]
[Music] the login is clicked
the login is clicked we close this and here you can see we
we close this and here you can see we have the true value given over here
have the true value given over here next let's check
next let's check if the
if the login button
login button now this is selected method is basically
now this is selected method is basically used for the radio buttons and the check
used for the radio buttons and the check boxes mostly it determines whether
boxes mostly it determines whether the element is selected or not
the element is selected or not so this uh operation is only applied to
so this uh operation is only applied to input elements such as check boxes
input elements such as check boxes select option the radio buttons
select option the radio buttons to return that it is true or false if
to return that it is true or false if the radio button is selected it will
the radio button is selected it will return true if it is not then it will
return true if it is not then it will return false okay and it accepts nothing
return false okay and it accepts nothing as a parameter but it returns a boolean
as a parameter but it returns a boolean value so in this case this element is
value so in this case this element is not a radio button or a check box or
not a radio button or a check box or something but and it is not selected
something but and it is not selected also
also so obviously
so obviously it will return false so if i write
it will return false so if i write driver.find element dot x python is
driver.find element dot x python is selected and if i print this variable
selected and if i print this variable now let's see the output will be false
now let's see the output will be false because this element is not selected and
because this element is not selected and it is not a
it is not a radio button or a check box so my chrome
radio button or a check box so my chrome browser is launched it's navigated and
browser is launched it's navigated and the username and password is entered
the username and password is entered the username is cleared the password is
the username is cleared the password is also cleared and the login is clicked
also cleared and the login is clicked and here you can see the output is false
and here you can see the output is false okay so here these were the test cases
okay so here these were the test cases that we execute today we launched the
that we execute today we launched the chrome browser we opened the url we
chrome browser we opened the url we entered the username and the password we
entered the username and the password we cleared it
cleared it so here we use the clear operation
so here we use the clear operation here we use the uh send keys method and
here we use the uh send keys method and here we understood the difference
here we understood the difference between the click and the summit method
between the click and the summit method then we use the get text method the get
then we use the get text method the get location the get size and that get tag
location the get size and that get tag name then we understood the difference
name then we understood the difference between the fine element and the find
between the fine element and the find elements then
elements then we use the is displayed method is
we use the is displayed method is enabled method in is selected method so
enabled method in is selected method so this way we have covered all the web
this way we have covered all the web element commands
element commands so let us just understand the difference
so let us just understand the difference between all these elements
between all these elements i have explained the difference between
i have explained the difference between the click and the submit so for the
the click and the submit so for the click we have no restrictions whereas
click we have no restrictions whereas for submit method we have the
for submit method we have the restrictions that is the method is only
restrictions that is the method is only applicable if the buttons are inside the
applicable if the buttons are inside the form tag okay so this is the basic
form tag okay so this is the basic difference between the click and the
difference between the click and the submit and if the button is inside the
submit and if the button is inside the form tag or the button is outside the
form tag or the button is outside the form type the click method will work but
form type the click method will work but if the button is outside the form tag
if the button is outside the form tag that means the summit will not work we
that means the summit will not work we have seen the example also
have seen the example also next is the find element in the find
next is the find element in the find elements now the find element returns
elements now the find element returns the first matching web element if the
the first matching web element if the multiple web elements are discovered by
multiple web elements are discovered by the locator now if the locators
the locator now if the locators discovers multiple web elements like
discovers multiple web elements like suppose of name suppose the name given
suppose of name suppose the name given over here is the column one and there
over here is the column one and there are multiple column ones present on the
are multiple column ones present on the web page okay and it has multiple web
web page okay and it has multiple web elements are discovered over there so it
elements are discovered over there so it will return the first matching web
will return the first matching web element whereas in case of find elements
element whereas in case of find elements it will return a mult list of multiple
it will return a mult list of multiple matching web elements and it throws no
matching web elements and it throws no exception it is just that it returns an
exception it is just that it returns an empty list whereas
empty list whereas in fine element it throws no such
in fine element it throws no such element exception if the element is not
element exception if the element is not formed detects a unique web element
formed detects a unique web element whereas the driver.find elements it
whereas the driver.find elements it returns the collection of matching
returns the collection of matching elements this is the example we have
elements this is the example we have also seen the example of find elements
also seen the example of find elements next what is the difference between the
next what is the difference between the is displayed is enabled and is selected
is displayed is enabled and is selected now the is displayed method is used to
now the is displayed method is used to verify whether an element is on site
verify whether an element is on site present or not as i've shown the login
present or not as i've shown the login button was present on the web page so it
button was present on the web page so it displayed true so this method is used to
displayed true so this method is used to verify whether an element is present on
verify whether an element is present on the site or not
the site or not is enabled is used to confirm whether an
is enabled is used to confirm whether an element is enabled or disabled whereas
element is enabled or disabled whereas is selected is used to confirm whether
is selected is used to confirm whether an element is selected or not
an element is selected or not is selected is applicable to any web
is selected is applicable to any web object or any web element that is
object or any web element that is present on the web page and it returns
present on the web page and it returns true or false whereas is enabled is also
true or false whereas is enabled is also applicable to all the web object that is
applicable to all the web object that is present on the web page when it returns
present on the web page when it returns true and false
true and false now this is selected method is only
now this is selected method is only applicable for check box so the drop
applicable for check box so the drop down menus and the radio buttons on the
down menus and the radio buttons on the side and it will return true or false so
side and it will return true or false so if the radio button is selected it will
if the radio button is selected it will show true and if it is not selected it
show true and if it is not selected it will show false so this is the basic
will show false so this is the basic difference between the is displayed is
difference between the is displayed is enabled and the selected method so far
enabled and the selected method so far we have covered the web element commands
we have covered the web element commands we have understood the difference also
we have understood the difference also between the click and the summit the
between the click and the summit the find element and the find elements also
find element and the find elements also is displayed is enabled and is selected
is displayed is enabled and is selected i have also given the pdf sheet i will
i have also given the pdf sheet i will give all the links in the description so
give all the links in the description so that you can refer it also uh the source
that you can refer it also uh the source code link will be given in the
code link will be given in the description so you can check out the
description so you can check out the source code as well
source code as well so for now uh this is what we have
so for now uh this is what we have studied today in the next tutorial we
studied today in the next tutorial we will understand how to handle multiple
will understand how to handle multiple windows
windows through selenium webdriver so this is
through selenium webdriver so this is all for now
all for now so in today's tutorials we will cover
so in today's tutorials we will cover one of the most important interview
one of the most important interview question that is how to handle multiple
question that is how to handle multiple windows now in this tutorial we will
windows now in this tutorial we will understand
understand what is window handle we will understand
what is window handle we will understand some methods used for handling window
some methods used for handling window handles also we will cover some
handles also we will cover some interview questions on get window handle
interview questions on get window handle and get window handles
and get window handles now in the previous tutorials i
now in the previous tutorials i explained about the browser commands i
explained about the browser commands i explained all the commands except the
explained all the commands except the two commands that is the get window
two commands that is the get window handle and get window handles
handle and get window handles these are the two commands which is used
these are the two commands which is used to handle the multiple windows now for
to handle the multiple windows now for example this is the window now if i
example this is the window now if i click on this this is the new window
click on this this is the new window again if i click on this this is the
again if i click on this this is the next window
next window so these are the child windows and this
so these are the child windows and this is the parent window
is the parent window now the problem is how do i switch from
now the problem is how do i switch from this window to this window
this window to this window now sometimes you may come across a
now sometimes you may come across a complex scenario where you have to open
complex scenario where you have to open a new window okay and you have to
a new window okay and you have to perform some desired operation on the
perform some desired operation on the open window like for example this is the
open window like for example this is the parent window and by clicking on this
parent window and by clicking on this new window button i opened a new window
new window button i opened a new window and i have to perform some operation on
and i have to perform some operation on this so in this case how do i switch
this so in this case how do i switch from this window to this window
from this window to this window so this is what we're going to learn
so this is what we're going to learn today
today now handling multiple tabs or windows
now handling multiple tabs or windows may seem complex in the beginning
may seem complex in the beginning because it involves some different
because it involves some different commands which is new to you
commands which is new to you so as in beginner level so it will be a
so as in beginner level so it will be a complex in the beginning but once you
complex in the beginning but once you get get to know how to handle it and
get get to know how to handle it and once you get a hang of it it will be
once you get a hang of it it will be very easy for you
very easy for you now there are many ways to handle
now there are many ways to handle multiple windows you can use a
multiple windows you can use a javascript executor also method but we
javascript executor also method but we will be covering the basic method to
will be covering the basic method to understand how to switch between the two
understand how to switch between the two browsers
browsers now here if i want to switch from this
now here if i want to switch from this browser to this browser how am i going
browser to this browser how am i going to do that i'm going to use the window
to do that i'm going to use the window handles value now what is the window
handles value now what is the window handle value
handle value a window handle is basically a unique
a window handle is basically a unique identifier that holds the address of all
identifier that holds the address of all the windows it is basically a pointer to
the windows it is basically a pointer to a window which returns the string value
a window which returns the string value this is the window right this is the
this is the window right this is the parent window
parent window and this is the child window now if i
and this is the child window now if i want to switch from this to this i will
want to switch from this to this i will be using the window handles that is
be using the window handles that is basically the pointer or the address
basically the pointer or the address that is given to a particular browser
that is given to a particular browser for example if i assume this parent
for example if i assume this parent window is having a pointer of value some
window is having a pointer of value some string value it will be a very long
string value it will be a very long string value i'm just taking up an
string value i'm just taking up an example like suppose uh c21 okay and
example like suppose uh c21 okay and over here it will be uh something like
over here it will be uh something like d21 now if i want to switch from c21 to
d21 now if i want to switch from c21 to d21 how am i going to do that i'm going
d21 how am i going to do that i'm going to use some specific commands
to use some specific commands okay
okay and yeah these window handles are
and yeah these window handles are dynamic so it keeps on changing there's
dynamic so it keeps on changing there's no fixed value for it the dynamic in
no fixed value for it the dynamic in nature they will keep on changing and it
nature they will keep on changing and it is a pointer to a window which returns
is a pointer to a window which returns the string value okay
the string value okay so there are some predefined methods of
so there are some predefined methods of selenium that can be used to handle the
selenium that can be used to handle the windows first method is the browser
windows first method is the browser commands that i have
commands that i have explained before but i didn't uh show
explained before but i didn't uh show the practical implementation so we're
the practical implementation so we're going to implement it today so first is
going to implement it today so first is that the get window handles and the get
that the get window handles and the get window handle now there's a difference
window handle now there's a difference between the both of them
between the both of them the get fit to handles is used for
the get fit to handles is used for designing the window ids of multiple
designing the window ids of multiple open windows
open windows and get window handle is used for
and get window handle is used for retrieving the window id of the current
retrieving the window id of the current focused window for example now the get
focused window for example now the get window handles
window handles will retrieve the window id of this one
will retrieve the window id of this one as well as this child window and this
as well as this child window and this child window okay
child window okay whereas the get window handles will
whereas the get window handles will retrieve only the parent window handle
retrieve only the parent window handle value okay whatever value this window is
value okay whatever value this window is going to have that value it will drive
going to have that value it will drive through get window handle so this is a
through get window handle so this is a basic difference between the get window
basic difference between the get window handle and get window handles
handle and get window handles and the next uh method that is used that
and the next uh method that is used that is the switch to method now if you want
is the switch to method now if you want to switch from one window to the next
to switch from one window to the next window we will use the switch to command
window we will use the switch to command that will be driver dot switch to dot
that will be driver dot switch to dot window
window next uh how we're going to implement
next uh how we're going to implement this is we're going to execute three
this is we're going to execute three test cases today
test cases today the first test case will teach that how
the first test case will teach that how to print the value how to print the
to print the value how to print the handle values and we will learn the
handle values and we will learn the difference between the get window handle
difference between the get window handle and get window handles
and get window handles the next set of test case will teach us
the next set of test case will teach us that how to switch and navigate to the
that how to switch and navigate to the other sides
other sides also okay and the third test case we
also okay and the third test case we will know how to close the browser like
will know how to close the browser like the parent window we will close and then
the parent window we will close and then we will close the
we will close the child window how do we do that okay
child window how do we do that okay so let's first start with the first test
so let's first start with the first test case
case open your intelligent id id
so this is the java class that i have created or that is the selenium
created or that is the selenium tutorials 14 and i have created under
tutorials 14 and i have created under the package com.selenium and
the package com.selenium and these are the three basic commands that
these are the three basic commands that we always tried first to see opening the
we always tried first to see opening the chrome browser navigating to the url and
chrome browser navigating to the url and maximizing it
maximizing it okay
okay so
so first that open a chrome browser
first that open a chrome browser navigate to the url this is the new url
navigate to the url this is the new url so i'll simply just copy this and it's
so i'll simply just copy this and it's i'll paste it over here
i'll paste it over here [Music]
[Music] and i have to maximize the
and i have to maximize the window next we have to print the parent
window next we have to print the parent window handle okay the parent window
window handle okay the parent window handle is this this is the parent window
handle is this this is the parent window handle that we have
handle that we have and these are the child windows
and these are the child windows okay so we have to print the parent
okay so we have to print the parent window handles so what you're going to
window handles so what you're going to do is i will write driver
dot get window handle because i have to print the parent window handle so i'll
print the parent window handle so i'll use the get window handle over here
use the get window handle over here because this returns string so i will
because this returns string so i will store it in a string type of variable
store it in a string type of variable i'll name it as
i'll name it as parent
parent window handle
window handle so string parent window handle is equal
so string parent window handle is equal to driver dot get window handle
to driver dot get window handle next i'm going to print it
so i'll write s out the parent
the parent and i will write
and i will write parent window handle okay
parent window handle okay this will print the parent window handle
this will print the parent window handle value
value next it says i click on the new window
next it says i click on the new window or button three times that is
or button three times that is this one new window button three times
this one new window button three times for this i will be using the for loop
for this i will be using the for loop so i'll write for
so i'll write for int i
int i is equal to one
is equal to one i less than or equal to three and i will
i less than or equal to three and i will increment it
increment it next i will write driver
next i will write driver dot
dot find element
by dot x path and i will place the x path over here
and what operation do i want to perform is the click operation which is one of
is the click operation which is one of the web element command so over here i
the web element command so over here i have clicked three times now let me give
have clicked three times now let me give some time
some time so that we can see the execution
so that we can see the execution properly now let's execute this now my
properly now let's execute this now my chrome browser is launched
chrome browser is launched it's navigated
it's navigated it's maximized
it's maximized the window is opened
the window is opened this is the next new window
this is the next new window and this is the next one here you can
and this is the next one here you can see
see we have
we have three
windows over here okay this is the child window one the
okay this is the child window one the star window to the style window 3 and
star window to the style window 3 and this is the parent window
this is the parent window so i'll just close this
we have to print the window handles we have to print all the window has a
have to print all the window has a handle so
handle so so i will write over here
so i will write over here driver
driver dot
dot get window handles
now this get window handles returns set
so this get window handles returns a set of string type and why set because the
of string type and why set because the get window handles are unique in nature
get window handles are unique in nature so that's why it's set and i have named
so that's why it's set and i have named the variable window handles and is equal
the variable window handles and is equal to driver dot get window handles
to driver dot get window handles now because i want to print all of them
now because i want to print all of them what i'm going to do is i'm going to use
what i'm going to do is i'm going to use the for loop so i'll write for and over
the for loop so i'll write for and over here because it's of string type so i'll
here because it's of string type so i'll write string
write string and i'll name it as handle
and i'll name it as handle next uh the values from which is
next uh the values from which is it's going to store and handle is from
it's going to store and handle is from the windows handles and
the windows handles and here i will print it
here i will print it and now let's execute this
so my chrome browser is launched it's navigated
it's navigated [Music]
[Music] it's maximized the child window is
it's maximized the child window is opened
opened the second try window is click
the second try window is click the third child window
the third child window [Music]
[Music] now let's see their values
now let's see their values [Music]
[Music] here it is the parent window handle is
here it is the parent window handle is this is the parent window handle
this is the parent window handle this is these are the
this is these are the child window handles and the parent
child window handles and the parent window handles so here you can see there
window handles so here you can see there is a difference between get window
is a difference between get window handle and get window handles the get
handle and get window handles the get window handle it returns the window
window handle it returns the window handle of the currently focused window
handle of the currently focused window or tab here our currently focus window
or tab here our currently focus window tab is the parent window
tab is the parent window whereas the get window handles returns
whereas the get window handles returns all the windows that is handled or
all the windows that is handled or launched including the parent and the
launched including the parent and the child
child so that's why there are four window
so that's why there are four window handles over here including the parent
handles over here including the parent in the child there's a parent window as
in the child there's a parent window as well as a child window in this okay
well as a child window in this okay which are all dynamic in nature it is
which are all dynamic in nature it is having all unique values okay
having all unique values okay now there's a basic difference between
now there's a basic difference between the
the get window handle and get window handles
get window handle and get window handles our next test cases
our next test cases open the chrome browser navigate to the
open the chrome browser navigate to the url maximize we have printed the windows
url maximize we have printed the windows parent window handle also we have
parent window handle also we have clicked the new window button for three
clicked the new window button for three times then we have to print all the
times then we have to print all the window handles and then we have to
window handles and then we have to switch to windows okay now here comes
switch to windows okay now here comes the switching command that is the driver
the switching command that is the driver dot switch to dot window command okay
dot switch to dot window command okay so to switch to windows
here i will write so you're in the for loop itself first
so you're in the for loop itself first i'm printing the window handles and then
i'm printing the window handles and then i'm switching so first i will print to
i'm switching so first i will print to which window it is and then
which window it is and then i'll write driver dot switch to
i'll write driver dot switch to dot window and inside the window i will
dot window and inside the window i will write handle i have to navigate to
write handle i have to navigate to google
google so what i'll do that for that
so what i'll do that for that so basically it will switch and then it
so basically it will switch and then it will navigate to the google so here
will navigate to the google so here i will write driver dot get
i will write driver dot get and i will paste the google
and i will paste the google url over here and i will maximize it
url over here and i will maximize it driver dot
driver dot manage dot window
manage dot window dot
dot maximize so let's give the time limit
maximize so let's give the time limit over here i'll write thread dot sleep
over here i'll write thread dot sleep and i'll specify some time
and i'll specify some time here i'll write driver
here i'll write driver dot quit so that the browsers are closed
dot quit so that the browsers are closed my chrome browser is launched
my chrome browser is launched it's navigated it's maximized
it's navigated it's maximized the child window is open
the next child window is open the third child window is open
the third child window is open [Music]
[Music] next first the parent window will be
next first the parent window will be navigated to google.com
navigated to google.com the next style window will be navigated
the next style window will be navigated to google and will be maximized
to google and will be maximized [Music]
[Music] then the next style window will be
then the next style window will be navigated to google and maximized
navigated to google and maximized [Music]
[Music] and you're the third trial window will
and you're the third trial window will be navigated to google and it will be
be navigated to google and it will be maximized
maximized [Music]
[Music] so till now uh we have learned how to
so till now uh we have learned how to switch and navigate over here i'm
switch and navigate over here i'm switching and navigating to google okay
switching and navigating to google okay so this is what we learnt over here the
so this is what we learnt over here the next third case says that we have to
next third case says that we have to learn how to close the windows
learn how to close the windows now here i use driver.quits so it just
now here i use driver.quits so it just closed all the browsers
closed all the browsers including the parent window and the
including the parent window and the child window but if i use driver.close
child window but if i use driver.close it will close only the current window
it will close only the current window handle that is handling okay that is an
handle that is handling okay that is an execution
execution so
here what we'll do is
what we'll do is now over here currently there is no
now over here currently there is no window in current okay so what we're
window in current okay so what we're going to do is we're going to switch
going to do is we're going to switch first i'll use driver dot
first i'll use driver dot switch to window and
switch to window and here i will write the parent window i
here i will write the parent window i want to close the parent window first so
want to close the parent window first so i'll switch to parent window first
i'll switch to parent window first i will write driver dot
i will write driver dot close
close so while switching
so while switching let's write thread dot sleep
let's write thread dot sleep and i will give some time over here
okay the first is right we will switch to the parent window and then we will
to the parent window and then we will close it
close it next
next switch back to the other windows and
switch back to the other windows and quit the browser now at this point of
quit the browser now at this point of time there is no focused window after
time there is no focused window after closing the parent window handle there
closing the parent window handle there is no focus window so we have to switch
is no focus window so we have to switch back to some window for that i am using
back to some window for that i am using a string type of a variable i will name
a string type of a variable i will name it as last
it as last window
window i will use this variable so what i am
i will use this variable so what i am going to do is i am going to write
going to do is i am going to write driver
driver because i have to
because i have to switch
switch to the other windows
i'll write driver dot switch to dot window and i'm going
dot switch to dot window and i'm going to write
last window handle over here and i'm going to use the driver dot
and i'm going to use the driver dot quit command
quit command now to see the execution
now to see the execution properly i'll write thread
properly i'll write thread dot sleep
dot sleep and here i'll give
and here i'll give some time
here also i'll write thread dot sleep
sleep and i'll give some time
and i'll give some time okay so now let's execute this
okay so now let's execute this my chrome browser is launched
my chrome browser is launched it's navigated
it's navigated it's maximized and then the child window
it's maximized and then the child window is opened
is opened the next child window is open
the next child window is open and the third child window is open
and the third child window is open now the parent will will be navigating
now the parent will will be navigating to uh google.com
then my child window will be navigating to google.com and it will be maximized
to google.com and it will be maximized [Music]
[Music] again the same process
again the same process it will be navigated to google and can
it will be navigated to google and can be maximized
be maximized [Music]
[Music] again it will be navigated to google and
again it will be navigated to google and it will be
it will be maximized
maximized [Music]
[Music] so the parent window is closed first
so the parent window is closed first then it is switching to some tab and it
then it is switching to some tab and it is quitting the browser
is quitting the browser okay so here we have learned how to
okay so here we have learned how to close the parent window and how to close
close the parent window and how to close the other browsers also
the other browsers also so these are the three test cases that
so these are the three test cases that we executed the first one we learned
we executed the first one we learned that how to print the handle values and
that how to print the handle values and what is the difference between the get
what is the difference between the get window handle and get window handles
window handle and get window handles in the next uh test case we learned how
in the next uh test case we learned how to switch and navigate to the other side
to switch and navigate to the other side we were navigating to google and we were
we were navigating to google and we were switching through
switching through driver.switch2.windows command
driver.switch2.windows command in the third one we learned how to close
in the third one we learned how to close all the windows first we switched to the
all the windows first we switched to the parent window we closed it and then we
parent window we closed it and then we closed the other windows okay so these
closed the other windows okay so these are the three test cases that we
are the three test cases that we executed
executed next let's cover some interview
next let's cover some interview questions on get window handle and get
questions on get window handle and get window handles okay so one of the most
window handles okay so one of the most frequently asked interview question is
frequently asked interview question is that what is the difference between the
that what is the difference between the get window handle and get window handles
get window handle and get window handles now the main difference between the two
now the main difference between the two is that the get window handle returns
is that the get window handle returns the window value of the currently
the window value of the currently focused tab that is the parent window
focused tab that is the parent window handle right
handle right whereas the get window handle it will
whereas the get window handle it will return all the
return all the window handles including the parent and
window handles including the parent and the child windows as we have seen in the
the child windows as we have seen in the example
example now the return type of get window handle
now the return type of get window handle is string
is string whereas the return type of get window
whereas the return type of get window handles is set because the window handle
handles is set because the window handle is always unique and it is dynamic in
is always unique and it is dynamic in nature and it keeps of changing okay so
nature and it keeps of changing okay so that's the reason why it is set so this
that's the reason why it is set so this is the basic difference between the get
is the basic difference between the get window handle and get window handles
window handle and get window handles [Music]
[Music] okay so the next interview question is
okay so the next interview question is how to switch to another window in
how to switch to another window in selenium now to answer this question i
selenium now to answer this question i divided the answer into two parts the
divided the answer into two parts the first is that define the
first is that define the methods of selenium that can be used for
methods of selenium that can be used for handling the multiple windows in an
handling the multiple windows in an application and those methods are the
application and those methods are the get window handle and the get window
get window handle and the get window handles
handles switch to end window these are some of
switch to end window these are some of the methods that will be used
the methods that will be used to
to handle multiple windows in an
handle multiple windows in an application so explain this first
application so explain this first and then explain the steps the steps are
and then explain the steps the steps are similar to the uh
similar to the uh test cases that we executed that is get
test cases that we executed that is get the handle of the parent window by using
the handle of the parent window by using the command driver dot get window handle
the command driver dot get window handle print the parent window then find the
print the parent window then find the element we found the element through
element we found the element through xpath so you can use any of the element
xpath so you can use any of the element locator now open multiple child windows
locator now open multiple child windows it through the child windows we use the
it through the child windows we use the for loop for this
for loop for this now get the handles of all the windows
now get the handles of all the windows that are currently open using the
that are currently open using the command driver dot get window handles
command driver dot get window handles which returns the set
which returns the set why returning a set because it is
why returning a set because it is storing unique
storing unique values window handles right it is
values window handles right it is storing unique window handles so that's
storing unique window handles so that's why it's set
why it's set then use the switch to command to switch
then use the switch to command to switch to the desired window that is the driver
to the desired window that is the driver dot switch to dot window and then close
dot switch to dot window and then close the browser so these are the steps
the browser so these are the steps so that uh to handle multiple windows in
so that uh to handle multiple windows in an application okay
an application okay okay so the next interview question that
okay so the next interview question that is asked is what does the switch to
is asked is what does the switch to command do now basically the switch to
command do now basically the switch to command is used to switch between the
command is used to switch between the windows frames and pop-ups and when we
windows frames and pop-ups and when we deal with frames and pop-ups at that
deal with frames and pop-ups at that time we will understand how it works
time we will understand how it works okay
okay so now whenever the web driver uh
so now whenever the web driver uh launches a new chrome browser it is
launches a new chrome browser it is given a unique alphanumeric value called
given a unique alphanumeric value called the window handle
the window handle and how to switch between the windows is
and how to switch between the windows is that we use a
that we use a driver.swisto.window and the handle
driver.swisto.window and the handle value is given over here
value is given over here okay so this is what the switch to
okay so this is what the switch to command do now this is one of the most
command do now this is one of the most important question i was asked in an
important question i was asked in an interview this question so that's why i
interview this question so that's why i have mentioned this so as soon as you
have mentioned this so as soon as you launch a browser window do we get the
launch a browser window do we get the windows handle value
windows handle value the answer of this is yes
the answer of this is yes let's see this with an example so as the
let's see this with an example so as the question says that as soon as we launch
question says that as soon as we launch a browser vendor do we get the windows
a browser vendor do we get the windows handle value so here
handle value so here what i did is uh open the chrome browser
what i did is uh open the chrome browser i'm launching the chrome browser
i'm launching the chrome browser i'm launching the chrome browser and
i'm launching the chrome browser and here i'm printing system.order
here i'm printing system.order system.out.printlndriver.getwindowhandle
system.out.printlndriver.getwindowhandle let's see what output do we get
let's see what output do we get you have my chromebrowser is launched
you have my chromebrowser is launched [Music]
[Music] it is not navigated because i have not
it is not navigated because i have not given any url over here and here you can
given any url over here and here you can see
see this is the get window handle i have
this is the get window handle i have used the get window handle uh
used the get window handle uh command over here and i can see a window
command over here and i can see a window handle over here right
handle over here right so this means that as soon as you launch
so this means that as soon as you launch a browser window we can get the windows
a browser window we can get the windows handle value there is no need to
handle value there is no need to navigate to a url or something but as
navigate to a url or something but as soon as we launch the browser you will
soon as we launch the browser you will get the window handle
get the window handle next is it mandatory to load a url to
next is it mandatory to load a url to achieve the window handle value no as we
achieve the window handle value no as we have seen in the example
have seen in the example here we are not loading any
here we are not loading any driver.getelement command right we are
driver.getelement command right we are loading any url over here no right it's
loading any url over here no right it's it's commented over here you can see
it's commented over here you can see so
so we can still get the window handle so
we can still get the window handle so this shows that it is not mandatory to
this shows that it is not mandatory to load a url to achieve the window handle
load a url to achieve the window handle value
value okay this question is something very
okay this question is something very important
important so i was asked this question in an
so i was asked this question in an interview so that's why i have included
interview so that's why i have included this question
this question now if you close the browser and then
now if you close the browser and then call the get window handle or get window
call the get window handle or get window handles on driver
handles on driver you will get no such session exception
you will get no such session exception stating session id is null using the web
stating session id is null using the web driver after calling the quick
driver after calling the quick now basically it says that you open the
now basically it says that you open the chrome browser i just launched the
chrome browser i just launched the chrome browser i did not load the url
chrome browser i did not load the url and i'm quitting the browser
and i'm quitting the browser then i'm calling the get window handles
then i'm calling the get window handles and what type of exception do i get do i
and what type of exception do i get do i get this exception and what this
get this exception and what this exception states you will understand
exception states you will understand that okay
that okay now here you can see i have already
now here you can see i have already created this uh
created this uh example in which i have launched the
example in which i have launched the chrome browser i'm not loading any url
chrome browser i'm not loading any url i'm printing the get window handle value
i'm printing the get window handle value over here after launching the chrome
over here after launching the chrome browser and then again i'm calling
browser and then again i'm calling driver.get window handles i want to know
driver.get window handles i want to know how many window handles are present over
how many window handles are present over here okay after quitting the browser so
here okay after quitting the browser so let's see what output do we get over
let's see what output do we get over here
here let me execute this
let me execute this [Music]
[Music] okay
now here you can see uh we are launching the chrome browser the
we are launching the chrome browser the chrome browser launched successfully the
chrome browser launched successfully the chrome browser was started successfully
chrome browser was started successfully then not loading uh we are not loading
then not loading uh we are not loading the url but we are printing the get
the url but we are printing the get window handle value over here we got the
window handle value over here we got the window handle over here
window handle over here next after quitting the browser we were
next after quitting the browser we were trying to print the get window handles
trying to print the get window handles we were trying to know how many get
we were trying to know how many get window handles value are present over
window handles value are present over here for that the exception that we got
here for that the exception that we got is
is no such exception session id is null
no such exception session id is null using web driver after calling quit
using web driver after calling quit this is the exception that we found now
this is the exception that we found now see
see whenever this script is trying to find
whenever this script is trying to find an element after driver.quit or after
an element after driver.quit or after driver.close action in the selenium
driver.close action in the selenium script or after closing or quitting the
script or after closing or quitting the driver session that is the open browser
driver session that is the open browser is closed right and at that time we are
is closed right and at that time we are trying to find an element so at that
trying to find an element so at that time there is no session that is active
time there is no session that is active to find the elements the session id is
to find the elements the session id is null uh exception is thrown at that time
null uh exception is thrown at that time when we find try to find an element
when we find try to find an element after driver.quit or after driver.close
after driver.quit or after driver.close okay so this is what the this is what is
okay so this is what the this is what is the meaning of no such session exception
the meaning of no such session exception and session id is none
and session id is none let's move to the next interview
let's move to the next interview question that is does get window handles
question that is does get window handles method return handles in the same order
method return handles in the same order as the windows is launched the answer is
as the windows is launched the answer is no let's practically implement this now
no let's practically implement this now here i have created a html code in which
here i have created a html code in which there are links like open google
there are links like open google and here there is open facebook and then
and here there is open facebook and then there is open flip card and then there
there is open flip card and then there is open snapdeal okay these are the
is open snapdeal okay these are the links now does get window handles method
links now does get window handles method return handles in the same order as
return handles in the same order as window launches let's find the answer
window launches let's find the answer for this so i have already written a
for this so i have already written a code for this
code for this in which first we're opening the chrome
in which first we're opening the chrome browser i'm navigating to it and then
browser i'm navigating to it and then i'm clicking on facebook i'm clicking on
i'm clicking on facebook i'm clicking on flipkart i'm clicking on snapdeal i'm
flipkart i'm clicking on snapdeal i'm clicking on google these are the sites
clicking on google these are the sites that i'm clicking on and then i'm trying
that i'm clicking on and then i'm trying to find the get window handles and i'm
to find the get window handles and i'm printing it
printing it with the title so let's see
with the title so let's see which handle prints first
which handle prints first and according to the order this the
and according to the order this the order should be google facebook flipkart
order should be google facebook flipkart snapdeal this should be the order now
snapdeal this should be the order now let's see the order
let's see the order so here my chrome browser is launched
so here my chrome browser is launched it's navigated
it's navigated [Music]
[Music] and here you can see all the browsers
and here you can see all the browsers are opened
are opened [Music]
okay here the title is get window handle this is the parent window this is the
this is the parent window this is the parent window now the online shop online
parent window now the online shop online shop site india and this is a snapdeal
shop site india and this is a snapdeal this is flipkart this is facebook and
this is flipkart this is facebook and google so basically it's the parent
google so basically it's the parent window
window snapdeal flipkart facebook and google
snapdeal flipkart facebook and google but the order should be google facebook
but the order should be google facebook flipkart snapdeal okay so there is a
flipkart snapdeal okay so there is a different order so that this means that
different order so that this means that it is not necessary that the get window
it is not necessary that the get window handle will method will return handles
handle will method will return handles in the same order
in the same order okay so the answer to it is no
okay so the answer to it is no so this is all for today uh
so this is all for today uh we learned some selenium interview
we learned some selenium interview questions about the get window handle
questions about the get window handle and the get window handles which is very
and the get window handles which is very important and it is frequently asked
important and it is frequently asked also and we also learned the difference
also and we also learned the difference between the get window handle and the
between the get window handle and the get window handles we learned how to
get window handles we learned how to handle multiple windows we executed some
handle multiple windows we executed some test cases also so this is all for today
test cases also so this is all for today today we are going to learn about the
today we are going to learn about the drop down menus now basically a drop
drop down menus now basically a drop down menu is a menu that offers a list
down menu is a menu that offers a list of options and we can select one value
of options and we can select one value at a time
at a time for example
for example here you can see this is the drop down
here you can see this is the drop down menu i can select any one value at a
menu i can select any one value at a time so this is called a drop down menu
time so this is called a drop down menu now we will handle the drop down menus
now we will handle the drop down menus with the help of a special class called
with the help of a special class called as a select class
as a select class because here you can see when i inspect
because here you can see when i inspect this element
this element i can see the select tag so that is the
i can see the select tag so that is the reason why to inspect this to select
reason why to inspect this to select values in this drop down menu i will be
values in this drop down menu i will be using the select class
using the select class now the basic syntax of select class is
now the basic syntax of select class is that select i'll create a reference of
that select i'll create a reference of this
this new is equal to new select and i will
new is equal to new select and i will specify my web element over here so this
specify my web element over here so this is the syntax of select class next there
is the syntax of select class next there are different methods of select class
are different methods of select class we'll be covering all these methods that
we'll be covering all these methods that is the select by index select by value
is the select by index select by value select by visible text deselect by index
select by visible text deselect by index deselect by value deselect by visible
deselect by value deselect by visible text get options get all selected
text get options get all selected options and get first selected options
options and get first selected options the deselect by value deselect by index
the deselect by value deselect by index and deselect by visible text only works
and deselect by visible text only works for the multi select box
for the multi select box so what is multiselectbox we will cover
so what is multiselectbox we will cover that also
that also now there are different types of drop
now there are different types of drop down menus and we will be learning how
down menus and we will be learning how to inspect all these menus the first is
to inspect all these menus the first is the drop down menu with a select class
the drop down menu with a select class we have seen that example now
we have seen that example now next is the drop down menu with the
next is the drop down menu with the multi select options
multi select options and then there is a drop down menu with
and then there is a drop down menu with a bootstrap
a bootstrap so uh here you can see this is a drop
so uh here you can see this is a drop down menu with select class here you can
down menu with select class here you can see there is select tag and this is the
see there is select tag and this is the multi select i can select multiple
multi select i can select multiple values over here okay so this is the
values over here okay so this is the multi select list so we will be
multi select list so we will be inspecting these two lists first and
inspecting these two lists first and then we will learn how to inspect the
then we will learn how to inspect the bootstrap list
bootstrap list now uh when we are inspecting the drop
now uh when we are inspecting the drop down menu the first thing that we'll do
down menu the first thing that we'll do is first we'll find how many options are
is first we'll find how many options are present in the drop down menu we will
present in the drop down menu we will extract all those options and then we
extract all those options and then we will select the options from the drop
will select the options from the drop down menu through through three methods
down menu through through three methods the first is select by index select by
the first is select by index select by value and then select by visible text
value and then select by visible text okay so just open your intelligent idea
okay so just open your intelligent idea id first
id first now i have already created a java class
now i have already created a java class i have named it as silly name tutorials
i have named it as silly name tutorials under package com.selenium and i have
under package com.selenium and i have given three commas that is open the
given three commas that is open the chrome browser i have given the key that
chrome browser i have given the key that is the
is the webdriver.chrome.driver and the value
webdriver.chrome.driver and the value that is the executable chrome driver
that is the executable chrome driver file
file then next i have written webdriver
then next i have written webdriver driver is equal to new chrome driver
driver is equal to new chrome driver here i'm launching the chrome browser
here i'm launching the chrome browser next i'm navigating to the urls i've
next i'm navigating to the urls i've specified the url over here this is the
specified the url over here this is the page that we will inspect first i will
page that we will inspect first i will inspect the drop down menu and then we
inspect the drop down menu and then we will select the
will select the multi select list okay and then i'm
multi select list okay and then i'm maximizing the browser now first to
maximizing the browser now first to handle drop down menu first we will use
handle drop down menu first we will use a select class
a select class over here i'm going to write select i'll
over here i'm going to write select i'll create a reference variable so i'll
create a reference variable so i'll write select element
write select element new select
new select and here i will specify the web element
and here i will specify the web element now there are two options over here
now there are two options over here either i write driver
either i write driver dot find element
dot find element by dot
by dot x path and i will specify the x path
x path and i will specify the x path over here i will inspect this element
over here i will inspect this element here it is and here in selectors up i
here it is and here in selectors up i can see the relative x path i'll copy
can see the relative x path i'll copy this this is the first option
this this is the first option the second option is
the second option is the second option is if i copy this
the second option is if i copy this i'll simply cop i'll just copy this and
i'll simply cop i'll just copy this and i'll give a variable that is the web
i'll give a variable that is the web element
element i'll write your
i'll write your drop down is equal to driver dot find
drop down is equal to driver dot find elements by dot x part and this is the x
elements by dot x part and this is the x bar that i have given over here
bar that i have given over here and here i'll write select
and here i'll write select then i'll write select element i'll give
then i'll write select element i'll give a reference variable i'm just showing
a reference variable i'm just showing you the different ways you can use the
you the different ways you can use the select class
select class then new select
then new select and here i will specify
and here i will specify drop down that is the web element
drop down that is the web element variable that i have created over here
variable that i have created over here okay so these are the two methods you
okay so these are the two methods you can use a select class i prefer this one
can use a select class i prefer this one so
so i'll just comment this and we will
i'll just comment this and we will continue with this one okay
continue with this one okay so here i have written select i have
so here i have written select i have created a reference variable that is a
created a reference variable that is a select element is equal to new select
select element is equal to new select and i have specified the web element
and i have specified the web element that is the location of the drop down
that is the location of the drop down menu now
menu now here
here after creating a select class we will
after creating a select class we will find how many options are present in the
find how many options are present in the drop down menu so here i am going to
drop down menu so here i am going to write select element dot
write select element dot get options okay
get options okay so your get options
so your get options belongs to the select tag and
belongs to the select tag and through this option we will derive all
through this option we will derive all the
the options that are present in the drop
options that are present in the drop down menu okay
down menu okay now here i will store it in a list type
now here i will store it in a list type of a web element
of a web element i'll name this web element as options
i'll name this web element as options and is equal to select element dot get
and is equal to select element dot get options now here i will print so i'll
options now here i will print so i'll write s out
write s out i'll write options dot
i'll write options dot size now why i'm using the size function
size now why i'm using the size function over here is because i want to return
over here is because i want to return the number of elements in the list i
the number of elements in the list i want to see how many number of elements
want to see how many number of elements are present in the list okay
are present in the list okay then we will extract the values so let's
then we will extract the values so let's run this
run this my chrome browser is launched it's
my chrome browser is launched it's navigated
navigated it's maximized
here there is no value displayed because we are not selecting any value right now
we are not selecting any value right now we have just seen there are total eight
we have just seen there are total eight elements that are present over here
elements that are present over here let's check
let's check if i inspect this
if i inspect this here there is eight element that is one
here there is eight element that is one two three four five six seven eight
two three four five six seven eight there are total eight elements that is
there are total eight elements that is present over here
present over here okay here you can see it so the next is
okay here you can see it so the next is that we have to print them so for that
that we have to print them so for that we will be using the for each loop here
we will be using the for each loop here i have written four and over here
i have written four and over here because of inspecting the web element so
because of inspecting the web element so i'll write the web element and i'll give
i'll write the web element and i'll give it as
it as i'll give a variable as e
i'll give a variable as e and here because
and here because i have to
i have to print the options that are present
print the options that are present so i'll write options over here
so i'll write options over here and then i'll write a system.out.println
and then i'll write a system.out.println i'll write the values r
i'll write the values r and here i'll write e dot e dot get text
and here i'll write e dot e dot get text so let's execute this my chrome browser
so let's execute this my chrome browser is launched it's navigated
is launched it's navigated it's maximized and here you can see the
it's maximized and here you can see the values that is there please select then
values that is there please select then we have sunday monday tuesday wednesday
we have sunday monday tuesday wednesday thursday friday saturday
thursday friday saturday and year also we can see these value
and year also we can see these value please select sunday monday tuesday
first get first selected option returns the first selected option in the select
the first selected option in the select tag here you can see it
tag here you can see it is the first selected option in the
is the first selected option in the select tags and if we don't find it it
select tags and if we don't find it it will throw the exception no such element
will throw the exception no such element exception if the option is not selected
exception if the option is not selected so
let's execute this my chrome browser is launched
my chrome browser is launched it's navigated
the first option that we have selected is california over here you can see the
is california over here you can see the index that we have given zero so the
index that we have given zero so the first option that is selected over here
first option that is selected over here is california okay
is california okay now let's deselect the values
now let's deselect the values for that
for that we'll be using three commas at the
we'll be using three commas at the deselect by index deselect by value and
deselect by index deselect by value and deselect by visible text
deselect by visible text so first i'll write
so first i'll write select element dot
select element dot deselect
deselect by index okay now i want to deselect
by index okay now i want to deselect new york because i have selected new
new york because i have selected new york so i will be writing 0 1 2 3. new
york so i will be writing 0 1 2 3. new york is the third index so i'll write 3.
york is the third index so i'll write 3. now here i'll write thread
now here i'll write thread dot sleep
dot sleep let me give some time
and let's execute this my chrome browser is launched it's
my chrome browser is launched it's navigated it's maximized
navigated it's maximized and the values are selected california
and the values are selected california new york and washington and we saw the
new york and washington and we saw the new york got deselected
new york got deselected now next
now next we will use the next method
we will use the next method that is
that is deselect
deselect [Music]
[Music] by value so i'll write select element
by value so i'll write select element dot deselect by
dot deselect by value
value now i want to deselect
now i want to deselect washington
washington so the value of washington is washington
so the value of washington is washington so i'll simply copy this
so i'll simply copy this and paste it over here
and paste it over here okay now let's execute this
okay now let's execute this my chrome browser is launched it's
my chrome browser is launched it's navigated
navigated it's maximized and here you can see the
it's maximized and here you can see the three values that is selected
three values that is selected and the new york and washington is
and the new york and washington is deselected
okay now we will use deselect by visible
by visible text
text so i'll write select element dot
so i'll write select element dot deselect by visible text
deselect by visible text and here
and here i'll specify i will
i'll specify i will now here i want to deselect the
now here i want to deselect the california so the visible text that is
california so the visible text that is present over here is california
present over here is california so i'll copy this
paste it over here and let's run this
and let's run this my chrome browser is launched
my chrome browser is launched [Music]
[Music] it's navigated
it's navigated it's maximized and those three values
it's maximized and those three values are selected
are selected the new york and washington is
the new york and washington is deselected
okay so here i've used so here i'll write select element dot
write select element dot deselect by
deselect by visible text and url paste california
visible text and url paste california okay now so run this
okay now so run this launch the chrome browser
launch the chrome browser and maximize the web page and these are
and maximize the web page and these are the three elements that is selected
the three elements that is selected california new york and
california new york and washington and all are deselected now
washington and all are deselected now over here the deselect option works only
over here the deselect option works only with the multi select boxes
with the multi select boxes it does not work with the normal
it does not work with the normal drop-down box that we have it works only
drop-down box that we have it works only for the multi select for example if i
for the multi select for example if i work for the multi select box the
work for the multi select box the deselect option then
deselect option then in that case
in that case for example over here
i'm selecting monday so in this case what will happen if i write
what will happen if i write select element dot deselect
select element dot deselect by visible text
by visible text and here i'll specify monday itself
so it will show an error so my chrome browser is launched
so my chrome browser is launched it's navigated
it's maximized and here you can see the date selected
and here you can see the date selected is monday
is monday [Music]
[Music] but it shows an exception over here
but it shows an exception over here while deselecting monday shows an
while deselecting monday shows an exception it says that
exception it says that you may only deselect options of a
you may only deselect options of a multi-select
multi-select okay
okay so the deselect option works only for
so the deselect option works only for the multi select drop down menus and not
the multi select drop down menus and not for the uh drop down menus with the
for the uh drop down menus with the select class okay
select class okay so these are the different types of
so these are the different types of methods that we launched today that is
methods that we launched today that is the
the select by value select by index select
select by value select by index select by visible text and deselect by value
by visible text and deselect by value deselect by index and deselect by
deselect by index and deselect by visible text also we learnt the option
visible text also we learnt the option that is the
that is the get for selected options now this works
get for selected options now this works for validation then we have learned the
for validation then we have learned the method that is the guest get first
method that is the guest get first selected option also so these are the
selected option also so these are the different types of methods that is
different types of methods that is supported by the select class
supported by the select class so this is all for now in the next class
so this is all for now in the next class we will learn how to inspect the
we will learn how to inspect the bootstrap drop down menu
bootstrap drop down menu so today we're going to understand how
so today we're going to understand how to handle auto suggestion drop down
to handle auto suggestion drop down menus with selenium webdriver
menus with selenium webdriver well to understand how to handle auto
well to understand how to handle auto suggestions with selenium webdriver
suggestions with selenium webdriver firstly it is necessary to understand
firstly it is necessary to understand what basically order suggestions are for
what basically order suggestions are for example if i type selenium
example if i type selenium webdriver
webdriver now here you can see there are number of
now here you can see there are number of inputs given for selenium webdriver
inputs given for selenium webdriver so these inputs are known as auto
so these inputs are known as auto suggestion or autocomplete so we're
suggestion or autocomplete so we're going to automate this today
going to automate this today this is the page that we're going to
this is the page that we're going to automate today what i want is for
automate today what i want is for example suppose if i write the buy over
example suppose if i write the buy over here
here and i can see the number of inputs right
and i can see the number of inputs right so i'm going to click on this input and
so i'm going to click on this input and over here if i write indoor
and here also i can see there are number of inputs right
of inputs right so i will click over here so this is
so i will click over here so this is what we're going to inspect today
what we're going to inspect today so let's just open your intellij idea
so let's just open your intellij idea ide
ide okay so here i have already created a
okay so here i have already created a java class i have named it as selenium
java class i have named it as selenium tutorial 17 under package com.tutorials
tutorial 17 under package com.tutorials of selenium and i have written the three
of selenium and i have written the three basic
basic commands that we usually write first is
commands that we usually write first is opening the chrome browser for opening
opening the chrome browser for opening the chrome browser we write system.set
the chrome browser we write system.set property in which we have the key
property in which we have the key written that is the
written that is the webdriver.chrome.driver and the value is
webdriver.chrome.driver and the value is the chrome driver executable file
the chrome driver executable file next we have written web driver driver
next we have written web driver driver is equal to new chrome driver which will
is equal to new chrome driver which will launch the chrome browser
launch the chrome browser next we have navigated to the url so
next we have navigated to the url so this is the page that we want to
this is the page that we want to navigate to so i have just copied this
navigate to so i have just copied this url over here in driver.get command
url over here in driver.get command next i have written
next i have written driver.manage.window.maximize to
driver.manage.window.maximize to maximize the chrome browser so let's
maximize the chrome browser so let's just execute this
just execute this okay so here you can see the chrome
okay so here you can see the chrome browser is launched
browser is launched and it's navigated
and it's also maximized okay so our three uh so are these three commands are
three uh so are these three commands are working properly now let's uh automate
working properly now let's uh automate the auto suggestion
the auto suggestion drop down menus so this is the page and
drop down menus so this is the page and i want to click on this element so i
i want to click on this element so i will inspect this
also one thing like in the previous tutorial i explained about the drop down
tutorial i explained about the drop down menus which were of select class over
menus which were of select class over here there is no select class included
here there is no select class included so here you can see we have the input
so here you can see we have the input tag so i'll just copy this i'll go to
tag so i'll just copy this i'll go to selectors hub
selectors hub and here i can see the relative x path
and here i can see the relative x path since i want to click on this element so
since i want to click on this element so i'll just copy this x path
now here i will write driver dot find element
element by dot
by dot x path and i will specify this x path
x path and i will specify this x path over here
over here and i want to click on this
and i want to click on this so i'll write
so i'll write click
or let's do one thing uh
uh let me save this in a web element type
let me save this in a web element type of a variable
of a variable so i'll just write
so i'll just write from is equal to
from is equal to now i have saved this in a web type web
now i have saved this in a web type web element type of a variable i have named
element type of a variable i have named it as from
it as from so web element from is equal to driver
so web element from is equal to driver dot find element by dot x path and i
dot find element by dot x path and i have placed my x path over here now over
have placed my x path over here now over here i'm going to write from
here i'm going to write from dot
dot click
click first we will click on this element
first we will click on this element after inspecting uh so first we will
after inspecting uh so first we will click on this element
click on this element then what i want to do is i want to move
then what i want to do is i want to move my cursor downwards okay now during
my cursor downwards okay now during automation we often require to press
automation we often require to press enter or we need to move our arrow keys
enter or we need to move our arrow keys downwards or we need to use the function
downwards or we need to use the function keys or the tab or delete or enter okay
keys or the tab or delete or enter okay so we can use these keys through send
so we can use these keys through send keys command how is that possible so
keys command how is that possible so just have a look at the syntax so here
just have a look at the syntax so here are the keyboard keys so here you can
are the keyboard keys so here you can see we have the arrow key down so under
see we have the arrow key down so under the send keys command you just need to
the send keys command you just need to write keys dot arrow down which will
write keys dot arrow down which will move the arrow downwards okay
move the arrow downwards okay next we have arrow key up which will
next we have arrow key up which will move the arrow upwards then we have
move the arrow upwards then we have arrow key left right backspace ctrl key
arrow key left right backspace ctrl key alt delete enter shift space bar so
alt delete enter shift space bar so basically these are all the keyboards
basically these are all the keyboards keys that is given by using send keys
keys that is given by using send keys command you can press them
command you can press them okay so over here
okay so over here also we have the function keys like the
also we have the function keys like the f1 f2 f3 we can press these keys also by
f1 f2 f3 we can press these keys also by using the send keys command
using the send keys command usually you we use the action classes
usually you we use the action classes for the keyboard commands but since we
for the keyboard commands but since we haven't learnt about action class so
haven't learnt about action class so over here we will use the send keys
over here we will use the send keys command
command so here after clicking what i want to do
so here after clicking what i want to do is i'll write from
is i'll write from dot send keys and i first i will enter
dot send keys and i first i will enter some value that is dubai
some value that is dubai and after entering some value i want to
and after entering some value i want to move my cursor downwards right so i will
move my cursor downwards right so i will write send keys again and here i will
write send keys again and here i will write keys
write keys dot
dot arrow here you can see we have add alt
arrow here you can see we have add alt left arrow down
left arrow down arrow left arrow right so i'll just
arrow left arrow right so i'll just click on arrow down
click on arrow down now uh since uh first i clicked on this
now uh since uh first i clicked on this element then i entered some value that
element then i entered some value that is dubai and then i moved downwards and
is dubai and then i moved downwards and after moving downwards what i want to do
after moving downwards what i want to do is i want to press enter okay
is i want to press enter okay so again over here i'll write from
dot send keys and here i'll write keys dot
send keys and here i'll write keys dot enter
enter and here you can see we have enter okay
and here you can see we have enter okay so this is what i want now why i have
so this is what i want now why i have given a web element type of a variable
given a web element type of a variable over here because i want to make my code
over here because i want to make my code very systematic now if i did not give a
very systematic now if i did not give a web element type of a variable over here
web element type of a variable over here i mean uh you have to write again and
i mean uh you have to write again and again try dot find element the x part
again try dot find element the x part dot click then driver dot find element
dot click then driver dot find element again the x path then dot send keys so
again the x path then dot send keys so instead of that i have written web
instead of that i have written web element and i have given a variable from
element and i have given a variable from and then i have specified the x path and
and then i have specified the x path and after that i'm clicking i'm sending keys
after that i'm clicking i'm sending keys and then i'm moving downwards and then
and then i'm moving downwards and then i'm entering
i'm entering okay
okay so let's execute this
so let's execute this okay so my chrome browser is launched
it's navigated it's maximize and here you can see dubai
it's maximize and here you can see dubai and it's moved downwards
and it's moved downwards and it's
and it's entered so this is how we can automate
entered so this is how we can automate it okay similarly we're going to do to
it okay similarly we're going to do to this drop down menu also first i will
this drop down menu also first i will inspect this
go to inspect go to selectors hub and here we have the relative xpath i'll
here we have the relative xpath i'll simply copy this
simply copy this and i'll just write a web element type
and i'll just write a web element type of a variable first over here web
of a variable first over here web element 2 is equal to driver
element 2 is equal to driver dot find element
dot find element by dot x path and i will specify the
by dot x path and i will specify the relative x path
relative x path over here
over here okay so first i will click the drop down
okay so first i will click the drop down menu then i would then after that what i
menu then i would then after that what i want to do is i want to send some
want to do is i want to send some commands so let's send keys
commands so let's send keys um
um i'll write indoor
i'll write indoor you can specify anything over here then
you can specify anything over here then i'll write 2 dot again i'm going to
i'll write 2 dot again i'm going to write send keys since i want to move the
write send keys since i want to move the arrow downwards so i'll write keys
arrow downwards so i'll write keys dot
dot arrow down okay
arrow down okay let me specify some time over here
let me specify some time over here thread dot sleep and i specify 2000
thread dot sleep and i specify 2000 similarly here also i will specify
similarly here also i will specify thread.sleep i will specify the time
thread.sleep i will specify the time next after moving down i want to click
next after moving down i want to click on the
on the enter button okay so i'm going to write
enter button okay so i'm going to write 2 dot
2 dot send keys and here i'm going to write
send keys and here i'm going to write keys dot
so first i am clicking the element
clicking the element then i'm entering some value in it after
then i'm entering some value in it after that i'm moving the arrow downwards and
that i'm moving the arrow downwards and then we have to enter
then we have to enter okay
okay so let's execute this
so let's execute this so here my chrome browser is launched
it's maximized and you can see dubai is
maximized and you can see dubai is entered let's click similarly indoor is
entered let's click similarly indoor is entered and it's moving downward and it
entered and it's moving downward and it is
is clicked okay so this is how you can
clicked okay so this is how you can automate your
automate your auto suggestions drop down menus
auto suggestions drop down menus now that's it for this video i hope you
now that's it for this video i hope you have learned something new and
have learned something new and now check boxes are widely used on our
now check boxes are widely used on our web pages to offer multiple choices of
web pages to offer multiple choices of an option to the user it is basically a
an option to the user it is basically a gui that allows the user to make certain
gui that allows the user to make certain choices for the given options okay now
choices for the given options okay now the user may get a list of choices and
the user may get a list of choices and the checkbox records the choices made by
the checkbox records the choices made by the user the user can select either
the user the user can select either single choice uh or multiple choices
single choice uh or multiple choices okay so the user can make single choices
okay so the user can make single choices or multiple choices out of the given
or multiple choices out of the given list depending on their requirement okay
list depending on their requirement okay so first we will learn how to handle
so first we will learn how to handle these check boxes
these check boxes and then we will learn how to validate
and then we will learn how to validate them
them now the user will select the options
now the user will select the options according to their requirement but as a
according to their requirement but as a quality engineer when you are becoming a
quality engineer when you are becoming a software tester
software tester what will you do with these with these
what will you do with these with these choices you're going to validate these
choices you're going to validate these choices okay that's what your work is
choices okay that's what your work is right as an automation tester you
right as an automation tester you perform test cases right so how we're
perform test cases right so how we're going to handle the checkbox that we're
going to handle the checkbox that we're going to learn first and then we're
going to learn first and then we're going to perform some validations on the
going to perform some validations on the check boxes
check boxes okay so here uh we will understand the
okay so here uh we will understand the validation through three commands that
validation through three commands that is the is displayed is enabled and is
is the is displayed is enabled and is selected we have covered these three
selected we have covered these three commands in the previous tutorials and i
commands in the previous tutorials and i have also explained the difference
have also explained the difference between these three commands okay
between these three commands okay so now uh this is the page that we're
so now uh this is the page that we're going to automate today here you can see
going to automate today here you can see we have the check boxes now you must be
we have the check boxes now you must be thinking how do we handle these check
thinking how do we handle these check boxes right it's very easy simply just
boxes right it's very easy simply just clicking on these check boxes it gets
clicking on these check boxes it gets checked and if you click again it is
checked and if you click again it is unchecked right that's what we're going
unchecked right that's what we're going to do to handle these check boxes so
to do to handle these check boxes so just open your intelligent idea ide so
just open your intelligent idea ide so here i have already created a selenium
here i have already created a selenium tutorial 18 java class
tutorial 18 java class in package com.tutorials of selenium and
in package com.tutorials of selenium and here we have written the three basic
here we have written the three basic commands that we write in all the
commands that we write in all the programs okay that is first launching
programs okay that is first launching the chrome browser to launch the chrome
the chrome browser to launch the chrome browser we write system.set property in
browser we write system.set property in which we involve the key that is the
which we involve the key that is the webdriver.chrome.driver and the value is
webdriver.chrome.driver and the value is the executable file
the executable file next we have written web driver driver
next we have written web driver driver is equal to new chrome driver which
is equal to new chrome driver which launches the chrome browser
launches the chrome browser now we have to navigate to the url
now we have to navigate to the url through driver.get command this is the
through driver.get command this is the page that we're going to navigate to so
page that we're going to navigate to so i have copied this url in
i have copied this url in driver.getcommand and then we are
driver.getcommand and then we are maximizing the browser so let's just
maximizing the browser so let's just execute this
execute this i'll
i'll run this here you can see my chrome
run this here you can see my chrome browser's launched
browser's launched it's maximized
it's maximized it's navigated and it's maximized okay
it's navigated and it's maximized okay so basically these three commands are
so basically these three commands are working properly
working properly now let's handle
now let's handle the check boxes
the check boxes okay
okay now to handle the check boxes uh
now to handle the check boxes uh generally what you do you just click on
generally what you do you just click on it right that's what we're going to do
it right that's what we're going to do we're going to perform the click
we're going to perform the click operation over here
operation over here first let's inspect this i'll just go on
first let's inspect this i'll just go on selectors up
selectors up and i'll just copy this relative x path
and i'll just copy this relative x path i will write driver dot
i will write driver dot find element
find element i dot x path
i dot x path and i will specify the
and i will specify the x path over here
okay so i will let me store this in a uh web element type of a variable i'll name
web element type of a variable i'll name it as
it as sports
sports because it's a sports check box
because it's a sports check box okay now what operation do we need to
okay now what operation do we need to perform over here we need to click this
perform over here we need to click this so i will write sports dot
so i will write sports dot click command
click command okay let us execute this
okay let us execute this okay so my chrome browser is launched
okay so my chrome browser is launched it's
it's navigated
navigated it's maximized
it's maximized and here you can see the spots is
and here you can see the spots is checked
checked okay
okay next
next again we will inspect
again we will inspect this element that is the reading element
this element that is the reading element checkbox
checkbox here it is so i will copy the relative x
here it is so i will copy the relative x path
path and again i will write
and again i will write web element i will write it as
web element i will write it as reading
reading is equal to
is equal to driver dot fine element
driver dot fine element by dot x path and i will specify the x
by dot x path and i will specify the x path over here
path over here okay
okay now what operation do i need to perform
now what operation do i need to perform over here is
over here is click
click so i'll simply just click this i will
so i'll simply just click this i will give some time limit over here so that
give some time limit over here so that we can see the execution properly
let me execute this again so you have my chrome brush is launched
so you have my chrome brush is launched navigate and maximize and here you can
navigate and maximize and here you can see the sports is clicked the reading is
see the sports is clicked the reading is also clicked
also clicked okay
okay so now the third web element so i'll
so now the third web element so i'll write web element dot
write web element dot sorry web element and i will specify the
sorry web element and i will specify the variable over here as music is equal to
variable over here as music is equal to driver
driver dot find element by dot
dot find element by dot x path
x path and
and i will just
i will just inspect this element and here it is so i
inspect this element and here it is so i will just
will just copy this x path
copy this x path and i will
and i will paste it over here
now what operation i need to perform over here is click operation right so i
over here is click operation right so i will just write music dot
will just write music dot click
click let's specify some time over here so
let's specify some time over here so that
that we can see the execution properly
i'll execute this so your uh my chrome browser is launched
so your uh my 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 sports is checked
sports is checked reading is checked
reading is checked music is also checked
music is also checked okay
okay now while handling these check boxes
now while handling these check boxes that is check and uncheck right so we
that is check and uncheck right so we have learned how to check these check
have learned how to check these check boxes let's learn how to uncheck them so
boxes let's learn how to uncheck them so if the check box is checked simply by
if the check box is checked simply by clicking it again it will uncheck right
clicking it again it will uncheck right so that's what we're going to perform it
so that's what we're going to perform it again
again so if we write uncheck so here i've
so if we write uncheck so here i've written uncheck and what i'll do is i
written uncheck and what i'll do is i will click all these elements again so
will click all these elements again so i'll just write sports dot
i'll just write sports dot click
click and then i will specify some time
and then i will specify some time red dot sleep
red dot sleep then again i'm going to write
reading dot click and and then i will specify some time
specify some time click and then i will specify some time
click and then i will specify some time over here sorry thread dot sleep
again i'll write music dot click just by clicking them again i'm going to
just by clicking them again i'm going to uncheck it okay
uncheck it okay so i'll write
so i'll write red dot
red dot sleep over here also
sleep over here also now why i'm re writing shred dot sleep
now why i'm re writing shred dot sleep is because i want to see the execution
is because i want to see the execution of the code properly okay so i am giving
of the code properly okay so i am giving a waiting time over here basically
a waiting time over here basically so let's execute this
so let's execute this and my chrome browser is launched
and my chrome browser is launched it's navigated it's maximized
it's navigated it's maximized sports is checked
sports is checked reading is checked music is checked
reading is checked music is checked sports is unchecked reading is unchecked
sports is unchecked reading is unchecked and music is unchecked
and music is unchecked okay so here we have learnt how to
okay so here we have learnt how to handle our checkbox so we can use the
handle our checkbox so we can use the click operation to handle the checkbox
click operation to handle the checkbox if we click it once it will be checked
if we click it once it will be checked if we click it again it is unchecked
if we click it again it is unchecked okay
okay now let's learn the validation part
now in validation i have explained three commands in the previous tutorials
commands in the previous tutorials so if you have seen all the tutorials
so if you have seen all the tutorials before i have also explained the
before i have also explained the difference between is selected is
difference between is selected is enabled and
enabled and is displayed okay so these are the three
is displayed okay so these are the three commands that we're going to use for
commands that we're going to use for validation first is display that is it
validation first is display that is it returns true or false if the element is
then we have the is selected then we have the is selected which
then we have the is selected which returns true or false
returns true or false if the element is
if the element is selected
selected okay
okay and next is is enabled
and next is is enabled so uh these three functions returns
so uh these three functions returns boolean values that is true or false so
boolean values that is true or false so it returns true or false if the element
it returns true or false if the element is enabled
is enabled okay
okay so these are the three commands for
so these are the three commands for validation
validation and your
and your let's validate it so first uh i have
let's validate it so first uh i have explained how to handle it so first we
explained how to handle it so first we are clicking the element like over here
are clicking the element like over here we are writing sports dot click so it is
we are writing sports dot click so it is clicked
clicked okay next we are unchecking it so it is
okay next we are unchecking it so it is clicked again it's unchecked now here
clicked again it's unchecked now here i'll first use the
i'll first use the is
is displayed
displayed okay
okay i'll just write
i'll just write sports dot
sports dot is displayed
is displayed okay
okay and
and i'll store this in a boolean type of a
i'll store this in a boolean type of a variable
so boolean bole one is equal to sports dot is displayed
dot is displayed and we're going to print this
and we're going to print this now if this boolean variable is
now if this boolean variable is displayed
displayed okay now if this bool one comes true and
okay now if this bool one comes true and if it is displayed it is true
if it is displayed it is true then we're going to write sports dot
then we're going to write sports dot click okay
click okay let's execute this
since it will show true because the element is displayed on the web page
element is displayed on the web page okay
okay here my chrome browser's launched
it's maximized and you can see sports is selected reading is selected music is
selected reading is selected music is selected sports is unselected reading is
selected sports is unselected reading is unselected and music is also unselected
unselected and music is also unselected and again sports is selected the reason
and again sports is selected the reason behind that is because the boolean value
behind that is because the boolean value is printing true and since we have given
is printing true and since we have given a condition over here if the boolean
a condition over here if the boolean value is true the spots will be clicked
value is true the spots will be clicked okay
okay similarly let's
similarly let's go for
go for is
is selected
selected okay so your if i write
okay so your if i write boolean
boolean volt2 is equal to
volt2 is equal to let's go for reading dot
let's go for reading dot it's selected
and next i'm going to write
next i'm going to write system.out.println and i'm going to
system.out.println and i'm going to print this
print this value
value okay
okay now let me give a condition now if
now let me give a condition now if boolean 2 is equal to
boolean 2 is equal to is equal equal to false now if it is
is equal equal to false now if it is false
false if it is not selected
if it is not selected then we're going to write
then we're going to write reading dot
reading dot click
click okay
okay now let's execute this okay so my chrome
now let's execute this okay so my chrome browser is launched
browser is launched it's navigated
it's navigated it's
it's maximized
maximized and you can see his post is clicked
and you can see his post is clicked reading is clicked
reading is clicked music is clicked sports is unclicked
music is clicked sports is unclicked reading is unclicked and music is also
reading is unclicked and music is also unclicked
unclicked and again this post is clicked and the
and again this post is clicked and the reading is also click the reason why it
reading is also click the reason why it is clicked because i have given
is clicked because i have given over here the condition is like bool 2
over here the condition is like bool 2 is equal equal to false and here the
is equal equal to false and here the output for
output for when we are writing reading dot is
when we are writing reading dot is selected the output is false why because
selected the output is false why because once we clicked it
once we clicked it and after that again we are unchecking
and after that again we are unchecking it right so if selected retrieves false
it right so if selected retrieves false if the element is not selected so here
if the element is not selected so here the element is not selected at this
the element is not selected at this point of time so the value of bulldo is
point of time so the value of bulldo is false and since it falls then it's
false and since it falls then it's clicking it again
clicking it again okay now let's let's go for is enabled
now again i'll write boolean bool3 is equal to
bool3 is equal to music
music bot is enabled
bot is enabled okay
okay next we're going to print it so i'll
next we're going to print it so i'll write
write 3
3 and here again
and here again i'll give a condition condition will be
i'll give a condition condition will be if
if o 3 is equal equal to
o 3 is equal equal to true
true if the value is true
if the value is true then music
then music dot
dot click
click just click the music check box
just click the music check box so let's execute this
so let's execute this okay so my chrome browser is launched
okay so my chrome browser is launched it's maximized and here this post is
it's maximized and here this post is clicked reading is clicked music is
clicked reading is clicked music is clicked
clicked sports is unchecked reading is unchecked
sports is unchecked reading is unchecked and music is also unchecked
and music is also unchecked and then again the spouse is checked
and then again the spouse is checked reading is checked and the music is also
reading is checked and the music is also checked
checked the music is checked because the value
the music is checked because the value of
of is enabled is true
is enabled is true okay and i have given the condition over
okay and i have given the condition over here as both 3 is equal equal to 3 so
here as both 3 is equal equal to 3 so boot 3 is equal equal to true so that's
boot 3 is equal equal to true so that's the reason why it's clicking the music
the reason why it's clicking the music element
so here we have learned how to handle the check boxes and here we have learned
the check boxes and here we have learned how to validate these check boxes okay
how to validate these check boxes okay so uh this is it for this video i hope
so uh this is it for this video i hope that you learned something new so try
that you learned something new so try these programs on your own and if you
these programs on your own and if you face any problem you can check out the
face any problem you can check out the uh github link that is given in the
uh github link that is given in the description
description uh also if you have any questions or any
uh also if you have any questions or any feedback use the comment section below
feedback use the comment section below in the
Click on any text or timestamp to jump to that moment in the video
Share:
Most transcripts ready in under 5 seconds
One-Click Copy125+ LanguagesSearch ContentJump to Timestamps
Paste YouTube URL
Enter any YouTube video link to get the full transcript
Transcript Extraction Form
Most transcripts ready in under 5 seconds
Get Our Chrome Extension
Get transcripts instantly without leaving YouTube. Install our Chrome extension for one-click access to any video's transcript directly on the watch page.