0% found this document useful (0 votes)
5 views

Selenium_Notes

The document provides an overview of automation testing, highlighting its advantages such as time reduction and improved software quality, while also noting drawbacks like high initial investment and the need for skilled personnel. It discusses various automation tools like Selenium and QTP, their features, and limitations, as well as the architecture of Remote WebDriver. Additionally, it covers concepts related to locators, XPath, CSS selectors, and common exceptions encountered in Selenium automation.

Uploaded by

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

Selenium_Notes

The document provides an overview of automation testing, highlighting its advantages such as time reduction and improved software quality, while also noting drawbacks like high initial investment and the need for skilled personnel. It discusses various automation tools like Selenium and QTP, their features, and limitations, as well as the architecture of Remote WebDriver. Additionally, it covers concepts related to locators, XPath, CSS selectors, and common exceptions encountered in Selenium automation.

Uploaded by

jamesmartine700
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Q1.

What is Automation testing


ANS: The Process of testing software using a tool without any manual process.
Reason:
Main: When we have to perform Regression testing.
SUB Reason:
1) When time has to be saved
2) When the same task has to be done several times.
ADVANTAGE
- reduce time
- we reduce human efforts.
- It works faster
- Improve the quality of S/W

DRAWBACK/LIMITATION/DISADVANTAGE
-Initial investment is high.
-We require a skilled person.
The work of an automation engineer is to convert test cases to test scripts.
TESTSCRIPTS:
It is a code or program written against manual test cases.
Per day we can convert 2 to 3 test cases to test script.
----------------------------------------------------------------------------------------------------------------
Tools of automation d=difference
1) Selenium:
It is an automation tool used to test web and mobile application
ADVANTAGE:
1) Open source and free to download.
2) Supports multiple OS, Programming languages, and Browser
1|Page
Disadvantage:
1) Can’t automate standalone application
2) Can’t automate barcode, captcha, OTP, network error, audio, video,
etc.
3) We are not going to get the immediate support.
2) QTP (quick test professional):
Advantage:
Supports all types of applications d
Disadvantage:
1) It was paid software d
2) It only supports windows d
3) Only supports VB-Scripts (Visual Basics Scripts) d

REMOTE WebDriver Architecture

1)SearchContext:
1) It is an interface
2) Used to search elements in the webpage
3) It has 2 abstract method
a) findElement() – In a web page if we have to find only a single element
we use this.
The Return type of findElement is webElement
b) findElements() – If we have to search more than one or multiple
elements we use this.
2|Page
The return type of findElements is List<webElement>
WHY?
1) Search the target webElement in the web page
2) Perform action on Targeted webElement

2)takesScreenshot:
1) It has only one abstract method
a. getScreenshotAs()
b. Ways to take screenshot
i. Webpage
ii. Web Element

WHY??
1) For better analysis of testScript failure we take SS.
2) Act as proof in a defect report.

3)javascriptExecutor:
It has 2 abstract method
1) executeScript()
2) executeAsyncScript()
WHY TO USE?
It is an interface user to perform the scrolling operation method horizontally and vertically
When the selenium method is not working that time we use the javascriptExecutor
Interface method.

4)WebDriver:
It is an interface which is going to control our browser.
It is an core interface in webDriverArchitecture
Method:
3|Page
1) get()
2) getTitle()
3) getCurrenturl()
4) getPageSource()
5) close()
6) quit()
7) manage()
8) navigate()
9) switchTo()
10) getWindowHandle()
11) getWindowHandles()

Date- 27/01/2024

advantages of maven projects


1 it gives folder structure
2 it gives continuous integration with frameworks
3 supports 2 types of softwares or plugins: 1. eclipse pluglin and 2. commandline plugin
4 supports jenkins and github

regression testing:
process of testing the unchanged areas after modification of a feature to check if it iis
impacted or not
it is a repetitive process so the company switches to automated testing to reduce time and
effort
automation testing: process of testing sw with the help of tools ex: selenium, qtp:quick test
professional

when the company switches to automation testing:


1. when the company starts regression testing
2. when time should be saved

4|Page
3. when you have to run same(repetitive) tasks again and again

test automation:
procedure to add tools to Java projects
>go to selenium.dev>downloads>download the the tool
> Paste the tool to the jar folder
> right click on the project and click build path to add a reference library

or
>go to svn repository
>search selenium
> Click on selenium java
> Click on the version to download

procedure to download edgeDriver:


> Check if the edge browser is there in the system
> Check the version
> How to download edgeDriver.exe
>selenium.dev>platforms supported by selenium
>click on browser> click on edge documentation
> Click on a version to download

5|Page
Date: 27/Jan/2024

remoteWebDriver
>WebDriver is used to control the system
>RemoteWebDriver is used to control one system from another system

QUESTIONS
Q. Types of inheritance in selenium?
Q. Types of Java concepts read in selenium?
Q. Where are you going to use inheritance concepts in selenium?

HTML
1. paired tags
2. unpaired tags

Q. What is a tag name?


Q. how to identify tagName?
Ans: The first word or the first letter that is Written inside the angular bracket is a tag
name

The attribute provides extra info about tags or elements.


Attributes are the combination of property/key and values.
In selenium attribute/property is called as AttributeName and the values are known as
AtrributeValue.

LOCATOR/SELECTOR
https://letcode.in/test
>create account
>click on signup

6|Page
>enter name
>enter email
>enter password
>click on check box
> Click on signup

LOCATOR:
It is a search criteria that is used to search the web element in the web page.
8 types
all locators are static methods.
we have to select the locator according to the priority

- findElement: used to find an element that is a single present webpage.


- there are 8 types of locator
- 8 types of locator
1. -id
2. -name
3. -class
4. -tagName
5. -linkText
6. -partial linkTest
7. -CSS
8. -xPath

TYPES OF LOCATORS/SELECTORS
================

1. identify (best locator for findElement())


2. name (best locator to findElement())
Best locator for findElement because it gives you unique values.
3. class (best locator for findElements() )
7|Page
4. tagname (best locator for findElements())
Best locator for findElement because it gives you the Same/duplicate values.
To check duplicate
1. Select the element you want to check
2. CTRL+F (Write the expression)
3. tagname[AttributeName = ‘AttributeValue’]
example: img[class=’_2puWtuW_3a3qyb_’]

5. linkText (best locator to find elements if the element is a link) used for anchor tag (WE
USE THIS WHEN WE HAVE LINK TAG)
------ linkText: text that is present in between the open and closing anchor tags is known as
linkText
If text is attached to your link is known as linktext.
It is case-sensitive.

6. partialLinkText (best locator to find elements if the element is a link)


Here we can pass both complete and partial text(for example instead of ‘devices’ we
can write ‘device’)
7.css (best locator to find elements if the element is an expression)

8.XPath (best locator to find elements if the element is an expression)

------ CSS and Xpath are the best locators for syntax or expression.
Q. When do we go for the CSS locator?
ANS: When the web element does not have an id class or name and is not a link also then
we go for the CSS locator

8|Page
Q. How to identify the CSS selector
Ans: By using syntax: tagname[AttributeName = ‘AttributeValue’]

DATE- 29/01/2024
Q. How to see the src code of the webpage?
Ans: Right-click on the webpage > click on inspect.

Q. How to see the source code of a web element?


Ans: 1. Mouse hover on element > right click > Click on inspect
2. Ctrl+shift+I > click on search element in page > drag and drop on targeted element.

FOR PANTALOON SEARCH PROGRAM


1. Launch pantaloons.com
2. Identify for search field using inspect
3. Using CSSselector select the search field
a. input[type=’text’]
b. input[placeholder='Search for products and more...']
4. use SendKeys to pass a value you want to find
5. find search icon and use click() method to perform a search function

DATE: 30/01/2024

- To slow down the speed of the loading process we use Thread.sleep(//time in ms) it will throw an
exception which we need to handle using throws
- Slow down the execution of the automation script.

In CSS and XPath locator we use the expression


If everything gives duplicate value we go for relationships. Like child parent grandparent

Steps to perform when we have to perform more than one action at one time.
 When we have to do more than 1 action we need to identify the element and store it inside a
variable.
9|Page
 With the help of a variable call method

The return type of findElement is WebElement

Date: 31/01/2024

Drawback of CSS Selector


 When the element is not having any attribute.
 Backward traversing is not possible.
 When we have a duplicate we can’t opt for CSS
Advantage of CSS
 It is faster than XPath.

XPATH
 It is also known as XML path
 IT provides the path or the address of the element
 It is also used to exchange data between the client and the server.
 It overcomes the drawback of CSS Selector.
 There are 2 types of XPath
o Absolute XPath.
o Relative XPath. (It has 7 types.)
 XPath by attribute
 XPath by text
 XPath by contains
 XPath by group index
 Independent and Dependent XPath.
 XPath by axes
 Correlated XPath

Relative XPath
We are going to write XPath from a child of the document it is known as Relative XPath
Keyword
1. . (dot) = means the current project
10 | P a g e
2. / = immediate child (Absolute XPath is represented by this)
3. // = any child (Relative XPath is represented by this)
4. [ ] = index value start form 1

For Selenium project


 JRE (Immediate Child)
 SRC (Immediate Child)
 Referenced library (Immediate Child)
 Drivers (Immediate Child)
o Chromedriver.exe (any child for the selenium project but immediate child for Drivers folder)
 Jar (Immediate Child)
o Selenium server 4.16.1 (any child for selenium project but immediate child for Jar folder)

Relative XPath:
1. Writing the XPath from Any Child of the document is known as Relative XPath
2. It is represented by ‘//’.
Why do we choose XPath?
1. When the element has only the text then we go for relative XPath
2. When the element is having a duplicate. To remove them we use XPath
a.
3. When the element is dynamic.(that can be changed)

a.

1. XPath by attribute
Ans: Identifying or searching the element on the web page based on the attribute
 Syntax: //tagName[@AttributeName = ‘Attribute value’]
 Operation to use at (findElements()): AND, OR, NOT
o When working with the concept of findElement we use these operations and can
only be used wirh xpath by attribute
 We can remove duplicate using xpath by attribute with the help of xpath by group index

Example:
Code

11 | P a g e
Output

Operations

Drawback of Xpath by Attribute


 When the element is having only text
 When an element is having a duplicate.

2. XPath by text
a. Search the element based on text.
Syntax: //tagName[text()=’textValue’].
Eg:

 Text value is case-sensitive


 We need to write the same complete text.
 This syntax supports Link text and Normal text.

Drawbacks or disadvantages of XPath by text


 We can’t enter the partial text value
o Can be resolved by Xpath by contains

12 | P a g e
 If the text has lengthy spaces (Non-breakable space present in the text)
 When we have a partial dynamic text value (Eg: Men (35,673))
o Can be resolved by

Date: 02/02/2024
3. XPath by contains
a. When we have to enter partial attribute value and partial text value then we
use xpath by contains
b. When the text consist of partial text value.
Advantage
 Support both attribute and text
Syntex for text: //tagName[contains(text(),’partialTextValue’)]

Syntex for Attribute:


- When the attribute value is very lengthy then we use xpath by contains attribute..
SYNTeX: //tagName[contains(@AttributeName,’partialAttributeValue’)]
Full value:

Partial value

Drawbacks/Disadvantage
 When the element is completely dynamic. (Partially it can support).
o It can be overcome in independent and dependent xpath.

4. XPath by Group Index:


When the element has duplicates then we use xpath by group index.
Here we identify the web element based on index value. The index starts from 1.

Syntax:
13 | P a g e
(xpath)[indexValue]

1. We need to use XPath syntax for groupindex


2. The number of item in inspect shows the index value
a. Eg: (//div[@class=’_3ri01T’])[3]

5. Dependent and Independent XPath


Identifying the dynamic web element based on fixed element. (dynamic element on the basis of
fixed element as reference)

Q. Why?
Ans. When the web Element is completely dynamic that time we use independent and dependent text
path.
 Independent means fixed element
 Dependent means dynamic element.

Steps:
1. Identify which is fixed and dynamic
2. Write the xpath for the fixed element
3. Update the xpath by backward traversing (/..) to find a common parent for fixed and dynamic
element(we use /.. until we can get the same parent for both element or it cover both fixed and
dynamic element)
4. Update the xpath for dynamic web element .

14 | P a g e
EXAMPLE
1. (//div[@class='_4rR01T'])[1]
2. (//div[@class='_4rR01T'])[1]/../../
3. (//div[@class='_4rR01T'])[1]/../..//div[@class='_30jeq3 _1_WHN1']

Note: TO move from one tab to another tab we need switchTo concept

Date: 01/02/2024

The type of Exception we get in selenium

- selenium.NoSuchElementException
-If internet is slow.
Solution: apply Thread.sleep(Time in ms)
-When the source code we wrote is invalid
Solution: compulsory check is it giving 1 of 1 or not
15 | P a g e
- selenium.InvalidSelectorException
-can also be named as InvalidLocatorException
-ClassName locator doesn’t allow multiple class names and spaces.
Solution: We can pass multiple spaces using cssSelector(“”).
- ElementClickInterceptedException
1. When the element is not able to perform the action
2. We get it when something is interrupted by the action in the middle or other element in
the web page
 Solution:Apply the concept of wait: Pass the thread.sleep(time according to the
function)

Date: 03/02/2024

Absolute XPath
- Writing the XPath from the root of the document is known as absolute XPath.
- It is represented by ‘/’. (Immediate child)
- It is very lengthy.
- It consumes more time.
- We use it when the web element is not identified by the relative XPath then only we go for absolute
xpath
Example:
Here we need to take the path from the root element that is HTML tag/

16 | P a g e
Onlu value A

Only value B

Only value C

Only value D

to target the first txtbox


- css locator= input[value='A']
- xpath by attribute= //input[@value='A']
- absolute path= html/body/div[1]/input[1]
to target second txtbox>
- css locator=input[value='B']
- xpath by attribute=//input[@value='B']
- absolute path=html/body/div[1]/input[2]
to target third txtbox>

17 | P a g e
- css locator=input[value='C']
- xpath by attribute=//input[@value='C']
- absolute path=html/body/div[2]/input[1]
to target the fourth txtbox>
- css locator=input[value='D']
- xpath by attribute=//input[@value='D']
- absolute path=html/body/div[2]/input[2]
target combination of AB
- absolute path=html/body/div[1]/input
target combination of CD
- absolute path=html/body/div[2]/input
target combination of AC
- absolute path= html/body/div/input[1]
target combination of AC
- absolute path= html/body/div/input[2]
target combination of ABCD
- html/body/div/input
target combination of AD
- html/body/div[1]/input[1]|html/body/div[2]/input[2]
target combination of BC
- html/body/div[1]/input[2]|html/body/div[2]/input[1]

Example for Flipkart5 on eclipse


package basic;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class Flipkart5 {

public static void main(String[] args) throws InterruptedException


{
// TODO Auto-generated method stub

18 | P a g e
ChromeDriver cd=new ChromeDriver();
//Launch the Flipkart
cd.get("https://www.flipkart.com/");
cd.manage().window().maximize();
Thread.sleep(2000);
WebElement a =
cd.findElement(By.xpath("html/body/div/div/div/div/div/div/div/div/div/
div/div/div/div/header/getdiv/div[2]/form/div/div/input"));
a.sendKeys("Shoes");
a.sendKeys(Keys.ENTER);
}

Drawback:
1. It is very lengthy
2. Consume more time
3. If any element is added or removed from the structure, it needs a maintenance effort. (Update)

Core relative Xpath


Going back to the path until we get the element 1 of 1
EXAMPLE Xpath: //a[1]/div/div/div/div/img

19 | P a g e
Date: 05/02/2024
Type of interface
1) Search context: To search an Element in the WebPage then we use the interface called as
searchContext. It has 2 type
a. findElement();
i. returntype: WebElement()
1. To search single element in the webpage
2. Id and name are the best locator
3. Priority to ID
4. Exception: NoSuchElementException
b. findElements();
i. Return Typr: List<WebElement>
1. To search multiple element in the webpage we use findElements
2. Classand TagName are the best locator
3. Priority to TagName.
4. Exception: EmptyListWebElementException

Note: When we have text or linktext we should give the priority to text
2) WebDriver
- Also known as a core interface in selenium WebDriver architecture.
- It accesses the maximum number of methods. (Total 13)
- It is used to control the browser.
- It is also known as browser controlling methods.
- WebDriver interface have 11 abstract method.
1. get(String URL)
 used to launch the application
 It is compulsory to pass the main URL.
 It is having infinite number of waiting. It won’t stop by itself we manually
have to stop if our internet is slow.
 We have to enter complete URL.
2. getTitle()
 To get title of current webpage.
 Return type of this method is String.

20 | P a g e
3. getCurrentUrl()
 Get the title of the current webpage.
4. getWindowHandle()
 We use this method to get the current window ID. (d)
 It will always give the id of the parent window (d)
 It will only give single ID (d)
 Return type is String. (d)
 Why? We need it because if we want to transfer the control from one tab
to another tab we would require to know where our control is.
5. getWindowHandles() (Difference between windowHandle and window
handles)
 To get multiple or all windows id’s
 Return type is Set<String>
 It will give multiple id
 It give the id’s of both parent and child.
 Different id every time the program runs
6. Close() (Difference between close() and quit())
 Used to close the Tab/window.
 It will close only one tab/window
 It doesn’t stop the server
 It will close the Parent Tab (By default the control will be in the parent
window.)
7. Quit()
 It will close the tab/window
 Will close all the tab/window
 It will stop the server
 It will close all parent and child Tab.
8. Manage():
 Return type is ‘option’
 We are going to handle:
 Window related operation
 maximize():
o To maximize our screen we use this method
 Minimize():
o To minimize our screen we use this method
 fullScreen():
o We can make our window fullScreen
 getSize():
o Return type of this method is “dimension”
21 | P a g e
o We can get the height and width of window
o We need to import dimension from selenium package not
from awt package
o To get height and width we can use variable.getHeight() OR
refvariable.getWidth()
 setSize():
o We can set the default height and width of window
o Return type is void.
o First we need to create object of the dimension

o
 getPosition()
o To get the default x and y position our browser is going to
launch.
o Return type is Point
 setPosition()
o We set the position of X and Y axis of the window
o We pass the value in pixel
o We need to import the package from selenium package.
o Return Type is void
o First we need to create an object of Point

o
 Cookies related operation
 Timeout related operation
9. Navigate():
 Return type is navigation
 We must use the Thread.sleep in navigation method
 For the browser navigate method shows the direction
 It provide browser history navigation(Provide direction to browser)
 Used to pass Sub-URL
 Methods()
 Back()
o Backward direction
o Return type is void
 Forward()
o Forward direction
22 | P a g e
o Return type is void
 Refresh()
o Refresh the page
o Return type is void
 To(String URL)
o To enter the sub url we use To(String URL)
o Return type is void

Note: Only javaScript popup is known as blocker popup

10. switchTo()
1. To do end-to-end testing we need switchTo()
2. To transfer the driver control from one window to another window
3. 1 parent and 1 child window
4. Default the driver control will be present in Parent window
5. When we have to work in child window-switchTo() is required.

How to transfer driver control from parent window to child window?


1. We should know how many windows are there
a. To know this we call a method getWindowHandles()
2. To transfer the control we have to take the reference either getTitle() to
getCurrentUrl()
3. When we have more than one same element/window/frame we must use the
forEach loop
4. Then we put the if else condition using contains method having the child title which
we are going to pass the control to.

5.
How to transfer driver control from child to parent window?
1. Use a forEach loop
2. Store inside a variable
3. Get a title of parent tab

23 | P a g e
4. Use if condition checking if it contains the parent tab
5. If it contains parent title put a break to end the loop

11. pageSource()
 To get the source code of current page we use a method called
getPageSource()
 Return type is String

Q. Why we write webdriver driver = new ChromeDriver


Ans:
1. According to OOAD principal We should not store object in the class reference
and remote webdriver class ref.
3. We should store it inside an interface
4. We should not store the object in SearchContext TakesScreenshot and
JavascriptExecuter interface because all methods in the webDriver interface are not
accessible

WEB ELEMENTS
Action to be performed in WebElement
Why? To act on an element in the webPage we need to use webElement
What?
Ans: It is an interface, the element which is present on the viewPort area or visible
area
1. Search element in the webpage/Identify the element in the webpage
a. SearchContext (i): findElement()
b. Driver.findElement(By.locator()).click();
2. IT is having 14 abstract method
1. click()
i. to perform click operation
ii. Here we can get Exception as ElementClickInterceptedException
2. clear()
i. Clear the data in the web element (Example text fields)
3. sendKeys()

24 | P a g e
i. it can also perform clicking operation
ii. used to pass/perform two values/operation
1. To enter the data into text field
2. To perform some keyboard simulation
3. We use sendKeys to perform shortcut operation
Keys
 It is an enum (enumeration)
 IT is a java template.
 It contains all the keyboard keys as the constant(That means it’s work can’t be
changed)

4. getText()
i. Return type of text is a string
ii. This method is used to get the text of an element
iii. IT can get both normal and link text
iv. It is used to verify the text of the targeted element
5. getAttribute()
i. It will return the value of the given attribute name.
ii. return type is string
iii. if the given attribute is doesn’t contain then it will return null.
6. getCssValue()
i. This method also return the attribute value for the given attribute name.
7. getTagName()
i. It gives you the tag name of any element.
8. isEnable()
i. Reurn type is boolean
ii. We use it to check whether our element is enabled or not
iii. If element is enable it gives True if not it gives the False value
iv. IF the element is disabled we can’t perform any action
1. It returns false in an disabled state.
v. IF the element is Enabled we can perform any action.
1. It return true in enabled state
Condition
2. It should have a tag-name as ‘Input’ or ‘Button’
3. If the tag name is something else we’ll get the false as output.
9. isSelected
25 | P a g e
i. Return type is boolean
ii. Used to check if the element is selected or not
iii. If the element is selected it returns true.
iv. If the element is not selected it return false.
v. Condition:
1. It is used to verify the radio button or check box
Note: If it’s used on some other element rather than check box or radio button the
default value or output will be false.
10.isDisplay()
i. Return type is boolean
ii. Used to check the targeted web element is visible on the webpage or
not. If yes it will return true if false it will return false.
11.submit()
i. it can also perform clicking operation
ii. It has some condition
1. It should have a tag name: button
2. It should have an attribute name: type=”submit”
3. It should present inside a form tag
12.getSize()
i. It return the height and width of the element
ii. Return type is dimension
13.getRect()
i. It is a combination of getSize() and getLocation()
ii. Its return type is rectangle
iii. It return heigt and width and X&Y value of the element
14.getLocation()
i. It gives the X and Y value of the element.
ii. Its return type is Point

//If we get captcha in the webpage to enter we must apply the Thread.sleep of 6-8 seconds and enter the captcha
manually

15.getScreenshotAs

SCREENSHOT
takesScreenshot
 It is an interface
26 | P a g e
 Used to take screenshot in selenium
 It has only 1 abstract method
o getScreenshotAs()
 It can be taken in two ways
o WebPage Screenshot
o WebElement Screenshot
Q. Why we take screenshot?
Ans: For the analysis of test script failure.
For adding it as a proof in test report.
ITestListener is the advanced testing tool used to take screenshot of failed testScript only it
ignore the pass test Script.

OutputType
It is an interface that contain 3 static variable which is used to specify the target ss for
getScreenshotAs(). The final variable are.
Screenshot can be taken in 3 ways
- FILE - file
- BYTES- Byte
- BASE64- String
By default screenshot extension will be png.
It will take screeshot of the visible page
Return type depends on the argument.
- If it’s FILE
STEPS TO TAKE SS
1. We need to downcast
2. We need to call a method takesScreenshotAs() and store it in the form of FILE.
3. Store the file in the variable as tempFile call absolutePath() to know the location of SS
4. Create the destination file.(When we have to store the screenshot in project)
a. Create a folder name images or anything
b. Create an object of FILE
c. In constructor pass the path of the file where we need to store.

i.
27 | P a g e
5. Copy the temp File class object given by temp file to the destination file using
copyFile. It is a static method (Move the file from tempFile to destinationFile)

a.
6. After execution refresh the project
To create a folder by automation we use apache common.io
If there are multiple pages with the same name getScreenshotAs will take a screensthot of
only last page. To overcome this we use a method of LocalDateTime. It captures the image
as on date and time.

WebElementScreenshot
 It is also an interface
Steps:
1. Identify the element which you need to take the screenshot.
2. Call geScreenshotAs and store it in FILE form.
3. Create a destination folder and pass the path of the folder

Actions Class
1. It is a concrete class of selenium
2. It tells the concept to perform the action of mouse and keyboard
3. It has 21 method but these 6 are imp
a. Mouse Hover
b. Drag and drop
c. Right click
d. Double click
e. Key up
f. Key down

4. Steps to perform action


a. Identify the targeted element

i.
b. Create the object class.

i.
28 | P a g e
c. While creating the object, Pass the WebDriver reference as an argument to the
constructor

i.
d. Call the appropriate action class non static method do the action

i.
e. Call the perform() method

i.
1) moveToElement(Webelement target): To perform mouse hovering on targeted
element
2) click(): To perform clicking operation on the entire webpage.
3) click(webElement Target): To perform clicking operation on the targeted element
4) contextClick(): To perform right-click operation anywhere on the webpage.
5) contextClick(webElement): To perform the rightClick operation on the targeted
element.
6) DoubleClick(): To perform double click operation on an entire webpage.
7) DoubleClick(WebElement target): To perform double click on a particular element
8) moveToElement(webElement ele, int xOffset, int yOffset): It will move the cursor from
the targeted element towards the left side of it and perform the action. And if we give
the negative value it will move to the right side.
9) moveByOffset(int xOffset, int yOffset): this medhod is used to move the mouse either
horizontally or vertically respected to given pixel value.
10) dragAndDrop: It will drag and drop tha particular element to the targeted
element
11) clickAndHold(): It will hold a random element in the webPage
12) clickAndHold(WebElement ele): it will click on particular element and hold. It
doesn’t click and move to next page
13) release(): To perform release operation on the webpage
14) release(webElement Targeted): to perform release operation on the targeted
element.
15) Perform(): To perform action on the webpage we use perform
16) sendKeys(CharSequence): It pass the value randomly on the webpage, used to
perform scrolling
17) sendKeys(webElement targeted, argument): it pass the value to the particular
element like enter the data, clicking, delete, backspace
18)

29 | P a g e
---------------------------------------------------------------------------------------------------------------

. Difference between click() and click(webElement ele) is that click is used to click on
the webpage whereas click(WebElement) is used to click on particular element.
. To move curser over any element we use moveToElement() after hovering
. DoubleClick()
. ---------------------------------------------------------------------------------------------------------------
. RightClick() aka ContextClick
. Difference between contextClick() and contextClick(webElement) is that contextClick
is used to click on randomly on the webpage whereas contextClick(WebElement) is used to
click on particular element.

How Action is performed?


. All the action will be performed when perform is called.
. All action is stored in action Array
. before calling actions method the element should be available in the DOM
. return type or almost all the method of Action class is action itself.
. Return type of perform is Void

SelectClass
. It is a class used to handle dropDown in selenium
. It is a concrete class in selenium package
. There are two types of drop-down. Single List and multi list.

30 | P a g e
. Using non static method of select class we can handle both the type of List box.
. It provides lot of selection and de-selection/with the help of select class we can select or
de-select the element in dropDown.

Steps to use select class:


1. Identify the target position of target dropdown using findElement. It should have a
tag name <select>.

a.
2. Create the object of select class.

a.
3. Pass the targeteListBox as input to the select class constructor.

a.
4. Call the non static method of select class to perform the desired action.

a.

METHODS OF SELECT CLASS


1. isMultiple()
a. It will check if the dropdown is single list of multi List dropdown.
b. Return Boolean.
c. If single it return false if multiList it return true.
2. getOptions()
a. To get all the options in the dropdown which is present inside select tag
b. Return type is List<WebElement>
c. It returns multiple options
d. It is used to verify all the options are in the proper order or not

e.
3. SelectByVisibleText()
a. To select the elements in the dropdown on the basis of text.
31 | P a g e
b. It is a parametrized method that accept the <OPTION> tag text in the form of
string
c. Return type is void
d. Pass argument in the form of String

e.
4. SelectByValue()
a. It is used to select the element of the dropdown using the value attribute of
the option
b. Pass argument in the form of string
c. Return type is void

d. ./basicSearch/
GetOptionsOrangeHRM
5. selectByIndex()
a. It is used to select the element on the basis of index value
b. Index start from 0.
c. Return type is void
d. Pass argument in the form of string.

e.
6. deselectByIndex()
a. It will be used to deselect
b. We use this method when we know the number of the options present.
7. deselectByValue()
8. deselectByVisibleIndex()
9. deselectAll()
a. It will deselect all the element selected in the dropdown
10.Amazon>language>changecountry or region>selectIndia

Synchronisation:
- It is a process of matching two different event according to the requirement of the
system to the desired outcome.
- Application loading speed depend on the internet.
- Automation script execution speed and automation will always be faster.

32 | P a g e
- If application loading speed and automation script execution speed both should be
matched then we get the proper output.
- If application loading speed and automation script execution speed both speed are
not matching we get the noSuchElementException.
- TO slowdown the speed of execution we use delay(wait).

There are 5 types of wait


1. Implicit Wait
 It is applied onlluuy to the line were we wrote findElement() or
findElements()

 We get noSuchElementException findElement() or


emptyList<webElemenrt> for findElements()
 It has 500ms polling period/time, interval/wait frequency.
 It is also called intelegemt wait coz it saves time.
 We write
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
 For NO CONDITION(When internet Is slow in implicit wait)

33 | P a g e

 For YES CONDITION(When internet Is very fast)
 1st cycle----findElement()------element is present---perform the
action
 It will be applied in all the findElement() and findElements()
2. Explicit Wait
3. Fluent Wait
4. Thread.sleep():
 Alternate name: bilnd wait coz it won’t leave the control to the next line
till the given time is completed. In this we aplly the wait in the form of
mliseconds
 It is applicable only for current line
5. pageLoadTImeOut

34 | P a g e

You might also like