0% found this document useful (0 votes)
99 views79 pages

Understanding Selenium Automation Tools

Uploaded by

riya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views79 pages

Understanding Selenium Automation Tools

Uploaded by

riya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is Automation?

[Link] Manual test case into automation test script by using some automation tool is called as
Automation.

Why we go for Automation?


[Link] maintain the Accuracy in Repetitive Task

[Link] reduce the time for testing the Repetitive Task

[Link] reduce the Human effort

When we go for Automation?


[Link] the Application is Stable after the First Release

What are the two types of Application?


[Link] Application
[Link] Application.

What are all the Test Cases we are unable to Automate?


[Link] and Captcha related test cases
2.MP3 and MP4 related test cases
[Link] Related test cases
[Link] code and Gaming related test cases

Is 100 % automation is Possible? - Yes (expect the Above scenarios’)

[Link] is Selenium?
[Link] is a free and open-source web application automation tool
[Link] Testing application Tool.
[Link] where we can download the selenium for free?
[Link]
[Link] Is the Stable version of Selenium?
3.141.59
[Link] are the Flavors of Selenium?
[Link] Core,
2. Selenium IDE (Record & Play),
[Link] RC (Remote Control),
[Link] Web driver,
[Link] (Selenium Grid),
[Link],
[Link].
[Link] are the Browser’s supported by the Selenium Tool?
[Link] Chrome,
2. Internet Explorer,
[Link] Edge,
[Link],
[Link],
[Link] Firefox etc...

[Link] are all the Languages which will be getting supported by Selenium?
[Link], 8. Java Script,
2.C#, [Link] C,
[Link] [Link] JS,
[Link], [Link],
[Link], 12.R,
[Link], [Link],
[Link] [Link],

[Link] Selenium what type of Application can we Automate?


Only web Applications
[Link] Java topics required for Selenium
[Link] and Objects.
[Link] and Non-Static Methods.
[Link] Statements like if and if else
[Link] Statements like for, for each, while, do while.
[Link] Concept like Inheritance, Polymorphism, Encapsulation, Abstraction.
[Link] Framework like List, Set and Maps.
[Link] Handling.
[Link] of the String Class.
[Link] Handling.

[Link] Software’s?
[Link] (Java Development Kit)
[Link], Browser (chrome)
[Link] Jar Files
[Link] Executables (chrome driver .exe)
[Link] Web Application.

[Link] Selenium is an Open Source? How?


Yes, it’s is an open-source tool, it means we can across the source code
of selenium software itself, (we can download customize as per our
requirement)
[Link] are all the OS (Operating System) supported by Selenium?
[Link]
[Link]
[Link]
[Link] Unix flavor’s like Android, IOS, Ubuntu…etc.
[Link] are all the OS (Operating System) not supported by Selenium?
Unix Operating System is not supported by Selenium.
[Link] we do performance testing using Selenium?
No, but we can integrate selenium with the JMeter.
[Link] type of test cases we can automate?
Regression Testing
[Link] we automate Integration Testing?
Yes, Different type of the Test cases which is the part of the regression.
[Link] we automate the Negative test cases?
Yes
[Link] test Cases are automated First?
Smoke Test Cases (Sanity, Dry Run (Automation)), Build Verification
Testing (BVT), Skim (UAT).
[Link] 100 % automation is possible? If no why?
No, because we don’t have technology to automate the following
features or it may.
1.3D Games
[Link] of Audio and Video files
[Link] the Attendance using the Access cards & Biometric
Scanners, Entering the product details using the barcode scanner, payment
through credit card swiping.
[Link] (Completely Automated Public Turing test to tell
Computers & Humans Apart).
[Link] is browser & OS supported by the Selenium IDE?
Firefox and Windows.
Selenium Architecture

[Link] supports 14 different coding languages like Java, Python, Ruby etc.
They are called as Language Binding or Client Binding.
[Link] Client Library communicates with the Selenium stand Alone. Then the
server will perform the Action on the browser with the help of Driver
[Link] to perform the Action it uses JSON Wire Protocol (Java
Script Object Notation).
[Link] server internally contains Selenium Java Client binding also, hence
while installing Selenium we use only the [Link] file and Driver Executables.

Architecture of Selenium Web Driver


What is Selenium Web driver? (or)
Why we are using Web driver?
[Link] Web Driver is a tool is used to automate the web applications for
testing.
[Link] supports many browsers such as Chrome, Firefox, Safari and Internet
Explorer.
[Link] Super most Interface is Search Context, which is Extended by the Web
driver interface.
[Link] driver interface is implemented in Remote Web driver class.
[Link] Web driver class implements other interfaces also such as Java Script
Executor, Take Screenshot etc.
[Link] the browsers specified as classes such as Chrome Driver, Firefox Driver,
Internet Explorer Driver etc. extends to Remote Web driver Class.

How to Install Selenium?


[Link] installing selenium (Eclipse tool) check whether JDK has been installed
or Not
If not Download the JDK through -
[Link]
[Link] install the Automation Tool (Eclipse)
[Link]
Note: Apply Filter – Eclipse will display methods of Object class also we have
press control button after any variable. To hide it go to the Window tab in
eclipse preferencejava appearances type filters. Click on the Add
button & type java. lang. object then Click Ok & click on apply and close.
[Link] Selenium performs action on the Browser?
By Calling the native methods of the Browser.
[Link] protocol is used by selenium tool to interact / communicate with
the Browser?
JSON Wire Protocol (Java Script Object Notation).
History of Selenium
[Link] of Automation tool?
1)QTP – Quick Test Professional – Paid - UI Based Automation Tool
2)Selenium – Open Source – Script based Automation tool.

[Link] RC: (Remote Control)


[Link] is the first ever automation tool connected under the Selenium
Community, it is a script-based tool to automate the Web Application.
[Link] supports any language like Java, Python, Ruby, Pearl, etc.…
[Link] supports any Operating system like Linux, Windows, Mac, etc.…
[Link] supports any browsers like Chrome, Firefox, Edge, Opera, Safari etc.…
Limitations & Disadvantages
1.A separate RC server compulsory has installed it takes huge memory due to
this RC will lagger the performance.
[Link] can’t support secured web application
[Link] of Browser version is difficult
[Link] can’t support Desktop Application
[Link] IDE:
[Link] is one of the Automation tools under selenium community and it is an
open-source UI based automation tool.
Advantages
[Link] script creation is very easy
[Link]-technical persons can also perform automation
[Link] Execution is very easy
Disadvantages
[Link]’t able to automate the complex scenario’s
[Link] is no reusability of Common Scenario’s
[Link] only Chrome and Firefox browser’s
[Link] Driven Testing is not possible.
[Link] GRID:
[Link] Grid is an automation tool which supports Remote execution
[Link] Selenium Grid we can run Web driver script in multiple sub
machines
[Link] kind of Execution is considered as Hub node Execution.
[Link]
[Link] is an automation tool or Windows Desktop Application and it is a script-
based automation tool
[Link] Winium is not in use with the Web driver automation because web
driver is compatable with other 3rd party desktop automation tools to handle
desktop scenarios.
[Link] 3rd party tools are open source and much easier.
[Link] 3rd party tools for desktop applications are
a] AUTO IT
b] SIKULI
[Link]
[Link] is open-source automation tool for the Mobile Applications
[Link] support’s both android and IOS type of Applications.
[Link] WebDriver
[Link] is a most advanced highly efficient automation tool for Web Applications
[Link] is invented by Google on 2009
[Link] tool will support any programming language and any OS
4. This tool will support any browser
[Link] supports secured & non secured both the Applications (http & https)
[Link] supports other 3rd party Desktop Automation tool which Web driver is
compatible with it.
[Link] need of Separate RC server to run.
[Link] driven testing and the Framework creation is possible.
Disadvantages
[Link] will not support Desktop Automation tool
[Link] drawback is already overcome by providing compatibility other 3rd party
tools.
Methods of Search Context:
[Link] Element (By arg [ ] ) = Web element
[Link] Elements (By arg [ ] ) = List <Web Element>
Take Screenshot Methods:
[Link] ().
Web driver Methods: (No of Web driver Methods – 11)
1. Close () [Link] ()
[Link] () [Link]( )
[Link] () [Link]( )
[Link] () 8. manage ()
[Link] () [Link]()
[Link] ()
Java Script Executor Method
[Link] ()
[Link] ()
Web Element Methods: (No of Web driver Methods – 14)
1)Clear () 2) Click ()
3)Get Attribute () 4) Get CSS Value ()
5)get location () 6) Get Rect ()x
7)get Size () 8) get Tag name ()
9)get Text () 10) is Displayed ()
11)is Enabled () 12) is Selected ()
13)Send keys () 14) submit ()

Installation of Eclipse
[Link] a new Java Project called Automation & create two new folders called
Jar and Driver
[Link] to the Website ([Link] Click on DownloadsThen click on the
Stable VersionIt will download the Jar file).
[Link] down until find Browser Click on the Chrome Driver  Download
the Chromedriver32 bit (check the browser version and download)
[Link] the driver file and copy and paste it in the Driver folder created in the
Eclipse & same do the jar file as well
[Link] do right on the Jar folder and add the new Build path to the jar folder.
Demo Program

What is Upcasting? Why it is used in Selenium?


[Link] Sub class object into supertype is called as upcasting
Example: - WebDriver driver = new ChromeDriver ();
In selenium we use upcasting so that we can execute same script on any
browser.
Explain WebDriver driver = new ChromeDriver ();
Webdriver is an Interface.
Driver is a reference Variable.
= is an assignment operator.
New is a keyword to create an object
ChromeDriver () is a constructor to initialize the Object
; is the statement delimiter or used to end the Statement.
How do you enter url without using get method?
Using navigate ().to () method
driver. Navigate().to(“[Link]
What is the difference between get () & navigate ()?
By using get () we can enter the url only, whereas by using navigate () we can
enter the url, click on back, forward & refresh functions.
What is the difference between get () & to ()?
There is no difference between get and to method. To method is
internally calls get method, hence there is no difference between to & get
method. Both are used to enter the url.

How to close the browser without using close method?


By using quit ().
Ex: driver. quit ()
What is the difference between close () & quit ()?
Close () closed the Current Browser whereas quit () closes all the
browsers.
Write a script to Open [Link] & verify that title is google and also verify
that it is redirected to [Link] ?

Write a script to delete all the cookies present in the browser and maximize
the browser?
Write a script to print html source code (script) of the Webpage?

Web Element
[Link] present on the Webpage is called [Link] are
created using HTML Language (Hyper Text Markup Language)
[Link] HTML Elements contains three things
“Tags”, “Attribute” & “Text”.
Example: HTML Code of a Login Page
<div id =’d1’>Login</div>
In the Above Html code,
div is the Tag,
id is the attribute name
d1 is the Attribute Value
Login is the Visible Text
In order to see the HTML code of the required element right click on that
element& select the option ‘Inspect’, if Right click is disabled then
Ctrl+Shift+i , or press F12,it will display the developer’s tool bar.
In order to inspect another element, click on inspect button & then click on
required element.
In selenium, before performing any action such as clicking, typing, selecting
etc. we should find the elements by using Locators.
Locators
[Link] are used to find the Elements. In selenium there are 8 types of
locators & all of them are static method present in ‘By’ class.
[Link] is an Abstract Class
Syntax: - By. tagname ()
[Link] ()
[Link] ()
[Link] ()
[Link] ()
[Link] ()
[Link] LinkText ()
[Link] Selector ()
[Link] ()
[Link] Xpath
[Link] Xpath
What is the Return type of find Element?
Web element
What is the argument accepted by find Element ()?
By type
If specified locator is not matching with any of the Elements, then what find
element does?
It throws No such Element Exception
If the specified locator is matching with the Multiple Elements what find
Element does?
It will take the first available element & it returns the address of
First matching Element.
Write a program to Click google link elements by using Tagname, id, Name,
Class Name?
Link text & Partial Link Text
[Link] Link text and Partial Link Text locators are can be used to find the
link. If we try on any other type of element, we get No such element exception
Ex: -driver. findelement (By. link text(“Google”)). Click ();
If the text of the Link is changing, Partially link text.
Ex:- HTML Code of a Link is
<a…>Inbox (25) </a>
Selenium code
driver. findelement (By. PartialLinkText(“Inbox”)). Click ();
Limitations of Partial Link Text
[Link] should be a link
Ex:<span>Inbox (25) </span> //Cannot used
[Link] should be partially Changing
Ex:<span>30</span> //we cannot use partial link text

CSS Selector (Cascading Style Sheet)


[Link] selector is one of the locators in Selenium
Syntax: - tag [Attribute Name = ‘Attribute Value ‘]
<div id =’d1’>Login</div>
Ex: -div[id=’d1’]
Limitations of CSS Selector
We can check Css expression in the browser by using the following steps
[Link] any element
[Link] CTRL+F
[Link] the above Expression
1 of 1 One Matching Element
1 of 3  Multiple Matching element
0 of 0  No matching Element

Note: If we do any syntax mistake while writing the CSS expression ,then we
get Invalid Selector Exception
Xpath
[Link] is the path of the Element in the HTML Tree is called as Xpath. While
writing Xpath it starts with “.” Which also represents Current webpage on
HTML Document using “.” Is not mandatory.
[Link] navigate from Parent element to child element we use single “/”
Xpath Expression: - . /html / body / a (or) /html / body / a
Xpath in Selenium: - [Link]([Link]("./html/body/a")).click();The Above
XPath are called as Absolute Xpath.

Types of XPath
[Link] Xpath
[Link] Xpath
[Link] by Attribute
[Link] by text () function
[Link] by contains () function
[Link] in Xpath
[Link]-Dependent Xpath
[Link] by Group Index
[Link] Xpath
Starting from the Html Tag to the required or desired element is called
as Absolute Xpath.
Sample HTML Code
<html>
<body>
<div>
<a href=[Link]
<a href=[Link]
</div>
<a href=[Link]
<a href=[Link]
</div>
</body>
</html>
Link1  /html/body/div[1]/a[1]
Link3  /html/body/div[2]/a [1]
Link2  /html/body/div[1]/a[2]
Link4  /html/body/div[2]/a[2]
Link 1,2,3,4  /html/body/div/a
Link 1&3  /html/body/div/a[1]
Link 2 & 4  /html/body/div/a[2]
Link 1&2  /html/body/div[1]/a
Link 3&4  /html/body/div[2]/a

Question Scenario?
[Link] the browser
[Link] the Url
[Link] on the Zomato webpage
[Link] the browser
[Link] the Browser
Xpath by Index
[Link] Xpath, we can use Index which starts from 1,if there is another element
under the same parent with the same tag then the index become2 and so on.
Relative Xpath
/  child
//  descendent
Link 1  //div[1]/a[1]
Link 2  //div[1]/a[2]
Link 3  //div[2]/a[1]
Link 4  //div[2]/a[2]
Link 1&2  //div[1]/a
Link 2&4  //div/a[2] or //a[2]
Link 1,2,3,4  //a
Link 3&4  //div[2]/a
In relative Xpath, if starts with “// ” which represents descendent(Child,
Grandchild, Great grandchild…etc.)
Assignment?
[Link] the table ?--> //table//a
[Link] a Xpath for an Image ?

What is the Difference between //a & //table //a ?


// a matches with all the links which are present in any webpage
//table//a matches all the link inside the table.

XPath with Attribute


We can also use the Attribute of the element while writing the XPath.
The syntax is //tag [@Attribute Name=’Attribute Value]

Syntax ==>1) //tag[@An=’AV’]


 //tag[@An1=’AV1’]
 //tag[@An2=’AV2’]

Examples: - 1) //input[@type='text']
2) //input[@id='twotabsearchtextbox']

XPath with Text Function[text()]


In Xpath we can also use text (visible text)
Syntax is: //tag[text()=’textvalue’]
Html code: //div[text()=’Login ‘]
Xpath: //div[text()=’Login ‘]
Xpath with Contains
If text value is partially changing, we can use Contains () function on the
Xpath because in this type, version or value changes as an when new version
releases.
Usually if you see any number element in visible text it usually dynamic
in nature, it is likely to change in future
Syntax: //tag[contains(text(),’value’)]
Example:
//a[contains(text(),'Inbox')]

//a[contains(text(),'New meeting')]

How do you identify the element without using Partial Link Text?
By using Xpath with the Contains function
Example: html code:- <a>Inbox(25)</a>
Xpath://a[contains(text(),'Inbox')]
Note:
(For Links) We can use contains function for attribute also the syntax is
Syntax://tag [contains(@Attribute Name,’Attribute Value’)]
Example://img[contains(@src,'logo')]

Xpath with Traversing


Navigating from one element to another element is called as traversing.
There are two types of Traversing.
[Link] Traversing
Navigating from Parent element to child element is called as
Forward Traversing.
[Link] Traversing
Navigating from the Child element to parent Element is
called Backward Traversing
HTML Code:
<table border="1">
<tr>
<td>java</td>
<td>100</td>
</tr>
<tr>
<td>Selenium</td>
<td>200</td>
</tr>
</table>
Example for forward traversing {From html code to Selenium}
Absolute Xpath /html/body/table/tbody/tr[2]/td[1]
Relative Xpath  //td[.='Selenium']
Example for backward traversing {From Selenium code to HTML}
//td[.='Selenium']/../../../..
(/.. will move the cursor up to one level same as [Link].:)

Independent Dependent Xpath


If the value is changing completely then we handle it using Independent
Dependent Xpath
Here we use the Xpath using backward & forward traversing element
We always start from Independent element and ends with Dependent
Example: -1} //td[.='Selenium']/../td[2]
2} //td[.='java']/../td[2]
Steps to Construct html tree and write the Xpath
[Link] the Independent and Dependent element
[Link] Independent Element & place the mouse pointer on the source of
the Independent Element.
[Link] down the Html Code of the Independent Element
[Link] the Mouse pointer in upward direction in step by step till it highlights
both independent and dependent element, till it will common parent
[Link] the path Common parent above the code independent Element
[Link] down arrow key to navigate from common parent to dependent Element
[Link] its path below the Common Parent.

Xpath By Group Index


When writing Xpath expression we can write the expression within the
brace & we can specify the index outside the brace is called as Group Index.
Syntax:- (//tagname)[Index-Position]
Example:- (//td)[4]
(//a)[3]
Assignment
[Link] an Xpath to identify the Price of 1st T-shirt present in [Link]?
2. Write an Xpath to identify the image of HRK T-shirt present in [Link]/m?
3. Write an Xpath to identify the Price of Women Khushal dress present in
[Link]?
[Link] an Xpath to identify the image of Bonkids T-shirt in Kids section
present in [Link]?
[Link] an Xpath to identify Oneplus7t mobile phone present in [Link]?
Question
[Link] a script to remove the text function present in email text box of
[Link]?

[Link] a script to print height and width of email text box present in
Facebook?
[Link] a script to check whether the Facebook logo is displayed or Not in the
Facebook login page?

[Link] a script to check whether the Facebook login button is displayed or


Not in the Facebook login page?
Write a script to check whether checkbox is selected or not for Actitime
Application?

Write a script to login to the Actitime Application


[Link] the Browser
[Link] the URL [Link]
[Link] the Username and Password Username: admin, Password:
manager
[Link] on the Login Button
[Link] the Browser
Write a script check whether width of the username and password text box
are equal or not?

Write a script check whether width of the username and password text box
are aligned properly or not?
Write a script to click on the submit present in open-source billing application
without using Click method?
[Link]: -

Note: Submit method will work on when the type=” Submit “attribute is
present.
[Link]: -
Write a script to copy the text in email text box and paste it into Password
textbox for Opensource billing Application?

Write the script to check the Hidden password which is present in Open-
source billing application?

What are the frequently used locators in Selenium?


[Link],[Link],3. linktext,4. XPath
Write a script to print text of link “Forget your Password” in
[Link]?

Write a script to verify that the email text box present in Facebook login page
after giving the value intentionally check whether it is empty or not?

Write a script to remove the value present in text box of username without
using clear() in open source billing application?
Handling Multiple Elements
In order to handle multiple elements we will use findelements method.
Return type of the find elements is “List of Web elements”. List should be
imported from [Link] package.
If locators are matching with multiple element, it will return the address
of all the matching element.
If locators are not matching with any one of the element, then the find
element method will return the empty list
Sample HTML Code
Write a script to check the no of links present in the Html code along with
that print any particular link?

Write a script to count how many no of links present in [Link] and


print it on the console?
Write a script to print all the links present in [Link] but the input has
to be given from the Scanner Class?
Auto Suggestions
Write a program to print all the auto suggestions in the [Link] after
typing java in search text box and count the number of auto suggestions?
Or
Automate the following scenario
[Link] the browser
[Link] to the [Link]
[Link] ‘java’ in the search box textbox
[Link] all the auto suggestions and print count of Auto suggestions
[Link] the text of Auto suggestion
[Link] the first auto suggestion
Difference Between Find Element and Find Element’s
FIND ELEMENT FIND ELEMENT’S
Return type of the Find Element is Web Return type of the Find Element’s is
Element List<Web Elements>

If the locator is not matching it will Returns the Empty List


throw No such Element Exception

If the locator is matching with multiple It returns all the matching elements
elements, it will return the first
matching element
Used to handle the single element Used to handle the multiple elements

Write a script to print all the autosuggestion by using for each loop after
typing ‘selenium’ and select the last autosuggestion?

Automate the Following Scenario?


[Link] chrome Browser
[Link] to [Link]
[Link] iPhone in the search text box
[Link] all the auto suggestions and print the count of suggestions
[Link] the text of auto suggestions (Note you have to use for each
loop)
[Link] the last auto suggestion

Go to [Link] and type ‘t-shirt’ in from text box then print all the Auto
suggestions and select and select the Black T-shirts in it.

Synchronization
The process of matching the selenium speed with the application is
called as Synchronization.
Most of the time selenium is faster than the application because of the
reason, we may not get the expected result or we get exception such as ‘No
Such element Exception’
Example: using thread. Sleep method
Write a script for login and logout the [Link]
Implicit Wait
In selenium there are different ways to synchronize the [Link] of the
frequently used option is implicit wait
Syntax [Link]().timeouts().implicitlywait(10,[Link]);
It takes two arguments,1st one is long(duration) second one is Time unit
Time unit can be Days, Hours, Minutes, Seconds, Milliseconds, Microseconds,
Nanoseconds…
The specified duration is only used by Find element& Find Elements Statement
Means implicit wait will work only for the find element and find elements
function not for other functions
Default value of implicit wait is zero Seconds
When the control comes to any find element or find elements statement, it will
check whether the element is present or not.
If the element is present the find element method returns the 1st matching
element whereas find element’s method returns all the matching Elements.
If the specified element is not present then it will check for the Timeout
If time is over the find element method will throw the No such element
exception whereas find element’s method returns the Empty List
If the timeout is not over it waits for 500ms(1/2sec) which is called as Polling
Period.
Then it will continue to check whether the element is present or not.
Explicit Wait
In order to handle the synchronization of any method we can use Explicit
Wait.
Web driver wait itself is called Explicit Wait; we have to specify the
waiting condition explicitly.
Syntax
Webdriver wait = new Webdriverwait(driver,[Link](20));
[Link]([Link](“actiTime-EnterTime-Track”));

Flow Diagram
When the control comes to [Link] statement it will check the specific
condition
If the condition is true it will go to the Next statement, if the condition is false
it will check for the timeout.
If the time is over, it will throw the TimeoutException, else it will wait for
500ms & it will continue to check the condition.
Note: In the above flow diagram title is(“actiTime-EnterTime-Track”) conditions
Can we handle the synchronization of Find element method using Explicit
Wait? Yes.

Difference Between Implicit wait and Explicit Wait


Implicit Wait Explicit Wait
We do not specify the waiting condition We should specify the waiting condition
explicitly explicitly
We can handle synchronization of all Find We can handle synchronization of any
element and Find element’s method but only one at a time
After the time duration we get “No Such After the time duration we get “Time out
Element “Exception Exception”

Time duration can be days, hours, Time duration will be only in seconds
Minutes, Seconds, etc..

Custom wait
Handling the synchronization of the automation script by writing
own code is called as Custom wait.
Handling List box (Drop Down or Combo Box)
List Box is created using the Select Tag.
There are two types of List Box
[Link] Select List Box (Drop down or Combo box)
[Link] List Box
Content of the List Box is created using Option Tag
To handle the list box, we used Select Class of Selenium. It should be imported
from the following [Link]. [Link]
Select class has parameterized constructor it takes an argument of the type
Web element (i.e., address of the List Box). In order to select the required
option present in the List Box we can use any one of the following methods of
Select Class.
[Link](str)Takes String as an Argument
[Link](int)Takes Integer as an Argument
[Link] (Str) Takes String as an Argument
If the specified option is duplicate then it will select first matching option(in
dropdown list) and if the specified option is not present(text,value,index),we
get No Such Element exception.
Select Class can also be used to handle multiselect list box. In select class we
can also have the following of methods. This can be used on Multiselect List
Box
[Link] (Str)
2. deselectByIndex (int)
[Link] (Str)
[Link] ()
[Link] ()
[Link] ()
[Link] ()
[Link] ()
[Link] ()
If the specified option is duplicate in multiselect List box, it selects all the
matching option.

Write a script to select your DOB in [Link] after clicking on Create


New Account?
Ex:-
Handling Multiselect List
HTML code to create Multiselect List Box
Write a script to print the selected text in slv text box in the html page?
Write a script to print the count of all the selected options present in slv text
box?

Write a script to print all the options present in MTR LIST BOX.
Write a script to print all the options present in SLV LIST BOX but using
different for loop

Hash set
Hash set class extends Abstract Set class which implements Set interface.
[Link] Unique Elements
[Link] the Null Value
[Link] is not Synchronized
[Link] approach to search options
[Link] order is not Maintained
Write a script to print all the options present in MTR LIST BOX without
duplicates in sorted order?

Handling Pop ups.


In selenium, depending on popup we write different types of code to
perform action on the popup.
Popup are generally categorized as follows.
[Link] Script or alert popup or Confirmation Popup
[Link] division or Calendar Popup
[Link] Upload Popup
[Link] Download Popup
[Link] Popup
[Link] Window Popup
[Link] Popup
[Link] Popup

[Link] Script or Alert Popup (Confirmation Popup)


Characteristics:
[Link] cannot inspect this Popup
[Link] cannot move this popup
[Link] Popup will be having Ok button(alert) or it contains OK r Cancel button
(confirmation)
[Link] will be present below the address bar in the middle section

Solutions:
To handle alert or java script popup we can use [Link]().alert()
statement. After switching to alert popup, we can use
[Link]()to click on OK Button
[Link]()to click on Cancel Button
[Link]()to get the text which is present in Popup
[Link]()to type the text on the popup
All the above code works on Confirmation popup also, if the popup is alert
then there will not be any difference between the accept and Dismiss(Both will
click on Ok Button)
Hidden Division or Calendar popup
Characteristics:
[Link] can inspect this Popup
[Link] cannot able to move this popup
Solution:
We can handle hidden division popup by using
[Link]().method

Calendar Pop-up
[Link] the browser
[Link][Link]
dex-care
[Link] the policy Number-12345
[Link] on DOB (Req Date)
[Link] the Contact number and Click on Renew Button.
Note: In the most of the cases calendar popup will be hidden division
popup which will be handled using the find element statement.
File Upload Popup
HTML CODE <input type="file"id="cv"/>

New Folder
Robot Class
Robot class is Java class present in [Link](awt=Abstract
Window Toolkit)
Robot class works similar to the Sendkeys, whenever I want to perform
keyboard operation in windows, we go for Robot Class. We commonly use two
methods in the robot class
[Link]
[Link]-Release

Notification Popup
Characteristics:
[Link] can’t able to inspect this Pop-up
[Link] can’t able to move this pop-up
[Link] will have two buttons allow and block
[Link] is displayed below the address bar in the beginning similar to alert pop-up
Solution
To handle this popup we change the setting of the pop-up, so that
notification pop-up will not be displayed.
To change the settings of the browser we use add arguments method of
Chrome options Class
Note
Add arguments is an example for method overloading(it takes string or
list of string as an argument).
For every browser we have respective options class.
SoChrome options, Firefox Options, Internet Explorer options, etc.
In order to open the browser with modified setting we use
parameterized constructor in respective browser class.
newChromedriver()will open the browser in default setting
newChromeDriverOptions()will open the browser with modified settings.
This above statement is the example for Constructor Overloading

Authentication Popup
Characteristics
[Link] can’t move this pop-up
[Link] cannot inspect this Pop-up
[Link] pop-up will be having the username and Password textbox along with
the sign in and cancel button
[Link] Pop-up will be displayed just below the address bar middle section of
the browser similar to alert pop-up
Solution
To handle the authentication pop-up we send the username and
password along with the url inside the get method
url- [Link]
Username-admin
Password-admin

Child Window Pop-up or Child Browser Pop-up


Characteristics
We can move this popup & inspect this popup
This Popup will have maximize, minimize & close button along with the address
bar
Solution
To handle child window popup we use getwindowhandle() &
switchto().windows statement
Note
Address of the browser present on the desktop is called window handle
(section id)
In order to retrieve it we use getwindowhandle ().

URL[Link]

Difference Between GetwindowHandle & GetwindowHandles


GetwindowHandle GetwindowHandle’s

It will return the address of the current It will return the address of all the
browser browser’s
Return type is String Return type is Set<String>
Write a script to print the title or window Handle’s of all the browsers open
by [Link] ?

Write a script to print the address or window Handles of all the browsers
open by [Link] ?
How do you close all the browser’s without using Quit() ?
By using [Link]() inside the for each loop

How do you close all the child browser’s without using Quit() but not the
Parent browser has to be closed?
How do you close all the one particular child browser without using Quit()
but not the Parent browser has to be closed?
Summary of the Pop-up
Pop-up’s Solution

Alert Pop-up or Java Script [Link]().alertAccept,dismiss,gettext()


Popup
Hidden Division or Calendar By using find element() method
Pop-up
File Upload Pop-up Browser [Link](absolute path)

File Download Pop-up By using Robot Class(for chrome no need to


handle)
Print Pop-up By using Robot Class (for chrome we use
findelement)
Authentication Pop-Up By sending Username and Password along with
the URL inside the get() method
Notification Pop-up By using add arguments() method of the browser
options class(chrome options)
ChildWindow or Childbrowser By using Getwindowhandles() and
Pop-up [Link]().window() statement

Handling Tabs
Tab is also treated as new window in selenium
Here we are going to handle the tab in the same way as we handle child
browser or child window browser pop-up
Write a script to count the [Link] present in actiTime application after
clicking the actitime [Link]?

How do you close the Current tab? By using [Link]().


How do you close the all the tabs? By using [Link]().

Write a script to close all the Tabs without using quit ()?

Iterator
Iterator is an object that can be used to loop through the collections,
like Array List and Hash Set. It is called as “Iterator” because “iterating” is the
technical term of looping.
It should import from [Link] package
Note: Trying to remove items using a for or a for each loop would not
work correctly because the collection is changing size at the same time that the
code is trying to loop.
Write a script to close all the Tabs without using quit () and for each loop?
Write a script to automate the following scenario?
[Link] to the chrome and search for Wiprojobs
[Link] all the links present in the search page & print the URL of all the
links present in search page.

Write a script to automate the following scenario


[Link] the browser
[Link] the url([Link]
[Link] to the Application (Un: Admin, PW: manager)
[Link] on about your ACTi time present in help dropdown
[Link] on read service agreement link present in the popup
[Link] all the header present in license agreement tab
[Link] the agreement tab
[Link] the main browser.
Handing Mouse Actions
By using mouse, we can perform the following actions
[Link] Dropdown menu (By using Mouse Hover)
[Link] Click (Right Click)
[Link] and Drop
[Link] Click

How to Handle Dropdown Menu? (Or handling mouse hover)?


Mouse hover means your mouse pointer to a particular position
 Drop down menu is an element on which if we move the mouse
pointer it will display the list of options. To handle the drop-down menu, we
use “movetoElement ()” method of Actions Class.
 movetoElement () is nothing but mousehover.
 In selenium” Action is an interface & Actions is a Class”
 ” Actions” class is present inside the ‘Interactions Package’. “Actions”
class is mainly used for mouse hover actions.
 Actions Class has a parameterized constructor, where it takes web
driver as an argument whenever we call any method of actions class, we have
to use ‘perform method’ at the end of the statement.
Note: All the methods of Actions Class are Overloaded Method.
Write a script to open the ACTi-time link in new Window?

How do you perform double click in Selenium?


We can use actions class to double click on the Element
Example: - [Link](webelement).perform();
Write a script to perform drag and drop?

Automate the following scenario


[Link] to the V-tiger Application
[Link] Hover to resources tab & click on customers in the drop down menu
[Link] click on Read full story button and check whether Hacker Earth
Page is Displayed or Not.
Handling Frames
Webpage inside another webpage is called as Embedded Webpage.
Developers creates embedded webpage using iframe tag.
While automating the element, if it is present inside the frame we
should transfer the driver control into the frame using switchto().frame()
statement.
HTML Code for frames:

Write a script to send the values to T2 and T1?


Write a script to switching the frames from one to another?

Note: -In the above example frame method is overloaded. It takes only one
argument of any of the following 3 types
[Link] (index of the frame starts from Zero)
[Link] (id of the frame)
[Link] (address of the frame)
Nested Frame
1) [Link](0);
[Link](0);
[Link]()----Ok button
2) [Link]().parentframe();
[Link]().pf();
[Link]();-----Yes Button
Handling Disabled Elements and Scroll Bar
The executescript() method is declared in javascript executor interface
which is implemented in Remote webdriver class. Since we already upcasted
browser specific classes to webdriver interface, this (execute script()) method
will be hidden, I order to access this method we should downcast
it(remotewebdriver) or typecast the object to java script executor.

In order to validate the java script in browser inspect the element and
click on the console tab present in the developer tool bar and type the script
"[Link]('d2').value=\"manager\" for texting tn
Hidden box
[Link]('d3').click(); for clicking on Element
HTML CODE for HANDLING DISABLED ELEMENTS

Write a script to scroll 2000px vertically in [Link]


Write a script to scroll to the Particular Element in [Link]

Write a script to scroll to the Bottom of Webpage and get back to the top of
the Webpage in [Link]

Data Driven Testing


Testing the application with multiple test data which is kept in external
resource file like excel, property file and database etc. is called as data driven
testing.
Note: -
1)If we use index, we will not retrieve the same data if any data will add
or deleted tomorrow.
2)We get the same output even if new data is added in between
tomorrow if we use key value pair (of maps). Same concept is used to store in
the property file.
3)As per the rule of automation, test data should not be hardcoded
within the test script because modification and maintenance of test data is
difficult whenever we want to run the script with different set of data.
4)Instead of Hardcoding, get the data from external resource file and run
the test script. This is called as Data driven Testing (external resource might be
property file (. property) or Excel(.xlsx) or Database.
Handling Property File
In property file data will be stored in the form of key value pair.
Key and value should be separated by single space
By default, all the data present in property file is a string
Copy this code in notepad and save it as any file name with “.property”
extension.
Write a script to login to [Link] using Property file

Advantages of property File:


It is very light weight when compare to external resource file
It is faster in execution
In order to read the data from the property file we should get the java
object of the physical file by using fileinputstream class.
Then by taking the help of property file, load the file and get the value
by using the key {by using getproperty ()}

Disadvantages of Property File:


We cannot store more data in the property file because we need to
remember the key.
Handling the Excel File
In order to read the data from the excel file we need to use Apache Poi
plugin or third-party tool
By using apache poi we can read and write from all the Microsoft
documents like .xlsx,.xls,.ppt,.docx,.outlook,etc…
Apache poi is a free and open-source library tool like selenium.
Installation of Apache-Poi
[Link] to google and search for apache poi
[Link] on the first link and navigate to the apache poi community
[Link] on poi-bin-5.22 zip file under binary distribution
[Link] on the first link or url and download the zip file
[Link] the folder and copy all the jars present in the each and every folder
and paste it inside the jar folder of eclipse
[Link] to build path.
Note: -Make sure that all the jars available in lib [Link]-lib should be also
added to the jar folder in eclipse.
Write a script to read the data from the excel file?
Write a script to write the data from the excel file?

Write a script to read the multiple data from excel?

Advantages of Data Driven Testing


Reusability of common data and test script data
Modification of Data in excel and external resource file is easier
Maintenance of Data in Excel file ore external file is easier
Test data can be created explicitly before the test execution
We can test the application with the huge volume of data.
Generic Library
Generic library is one of the components of the automation framework
which contains common classes and common methods which can be reusable
for all the test script and any project as well.
Generic classes contain reusable methods which is created by framework
developers
All the generic classes will be present in separate classes and Package name
should be [Link]
Note: - Whenever we create any class or method we should follow the coding
standard as shown below
We should not make every method static because it will take more time to
execute so make it as non static.

Advantages of Generic Library: -


Common classes which can be used in any test script and any project
Reusability of codes
Code optimization
Test script development is faster
No need to put the effort to re-write the same program
No need to remember the syntax for every option
It can be easily shared to all the team members via Github.
Unit Testing Framework Tool
Junit java---------- 1 Test Ng(1,2)
Nunit.net----------2
PydevPython
Rspecruby
TestNG (Test Next Generation)
Test NG is a unit testing framework tool which is mainly used for batch
execution. (It is a third-party open-source tool).
Basically, testing is used by developers to perform unit testing and it is also
used in Selenium to perform black box testing.
Test Ng is a plugin for eclipse and it is inspired by Junit and Nunit with some
additional frames.
Advantages or Additional features of TestNg
Batch Execution(Run multiple test cases)
Group Execution(To run only smoke test cases or integration test cases)
Parallel Execution (Execute in Chrome, Firefox, MS Edge. In same time)
Generates the Reports automatically(HTML Report)
Listeners Features
Additional Annotations
Run only the failed test script
Installation of TestNG
Go to Eclipse and Click on help and select market place
Type Test Ng in search text box and click on Search button (Enter)
Click on Install button present under Test Ng for Eclipse
Click on confirm and select the radio button as I Accept License
Click on Finish (Click on Install anyway and restart now button)
 Another way of installing Test Ng
Eclipsehelpinstall new softwarework withtype
[Link]

After installation in order to check or verify TestNg tool is installed or not,go to


the eclipsewindowShowviewOthersexpand java folderSearch for
Test Ng
 After Testng Installation to the eclipse add Testng library for all the
projects in eclipse(required projects)
 Right click on the project go the build path and Select add libraries
 Select Testng & click on next and Click on Finish
Note: Whenever we using TestNg or TestNg classes we should not use the
following thing
 No main method (Do not use the main method)
 No [Link]();
 Do not use any default package
In case of Automation, unit testing framework tool like Test Ng will be used to
achieve batch execution without any manual interruption. And it will generate
HTML Report and also provide screenshot for the failed test [Link] order to
achieve batch execution every test script automation is executed using Testng
[Link] also handle Framework components during the batch
execution and it is the main controller of the framework.

Note: -
 Whenever we execute the above class it will automatically generate the
execution result(report) in HTML format
 In order to see it do the following procedure

Refresh the Java Project(F5) which will display the test-output


folder and right click on the emailable [Link] file. Go to
open with and Select Web browser.
 In order to open the report in Excel format right click on the report and
select export to Microsoft Excel and then click on Import and Ok.

[Link](“Hi”)Print only on the console


[Link](“Welcome to Test Ng” , true)Print on console & report
[Link](“Welcome to Tiffin Box”, false)Print only on the Report
[Link](“Welcome”)Print only on the report

You might also like