0% found this document useful (0 votes)
33 views154 pages

Software Testing: Manual vs Automation

The document discusses software testing, emphasizing its importance in delivering quality products and identifying defects. It outlines two main types of testing: Manual Testing and Automation Testing, detailing their advantages and disadvantages. Additionally, it introduces Selenium as a popular automation tool, explaining its components, advantages, and limitations.
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)
33 views154 pages

Software Testing: Manual vs Automation

The document discusses software testing, emphasizing its importance in delivering quality products and identifying defects. It outlines two main types of testing: Manual Testing and Automation Testing, detailing their advantages and disadvantages. Additionally, it introduces Selenium as a popular automation tool, explaining its components, advantages, and limitations.
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

Ranjeet kendre

Automation Testing

What is Software testing & why we need do s/w Testing?


Software Testing is a process of verifying a computer system/program to decide whether it
meets the speci ed requirements and produces the desired results. As a result, you
identify bugs in software product/project.
Software testing is basically an activity to identify and reporting defect on the software.
we are do s/w testing because of to deliver quality product to the customer and we will test
the application according to the customer requirement weather it need the customer
requirement or not

Two types of testing

1. Manual Testing
2. Automation Testing

Manual Testing
Manual testing is s/w testing process in which test cases are executed manually without
any automation [Link] the manual testing we have perform so many types of testing like
function non-function smoke database testing ,load testing, performance testing.

What is test cases


A test case is a set of actions performed on a system to determine if it satis es software
requirements and functions correctly. The purpose of a test case is to determine if different
features within a system are performing as expected and to con rm that the system
satis es all related standards, guidelines and customer requirements.

Retesting and Regression is a more important things because of these two retesting and
regression automation came into the picture So when u do manual testing so these are the
two areas where we need to put lot of time and efforts.

Re-Testing
Retesting is nothing but executing the same test case again and again with multiple set of
data.

Regression testing - Testing the xes whatever xes they have done and we need to main
focus on those xes weather these change working or not
and along with this we need to also make sure that other functionality should not affect
that's the basically called as a regression testing.

Regression testing de nition - Regression testing is use to ensure that the recent changes
does not affected the functionality.
Re-validating defect in newer builds and because of those xes make sure there is no side
effect. And in Regression testing we check rst failed test cases and along with that we all
the existing test cases.

Regression testing is required when there is

1. Changes in code
2. New feature is added
3. After Defect xing
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
Ranjeet kendre

Disadvantage of manual testing :

[Link] Testing is time - consuming mainly while doing regression testing.


[Link] Testing requires more time or more resources, sometimes both Time and
Resources.
3. Less Accuracy -(Human Users (Testers) may make mistakes, so we cannot expect more
accuracy in Manual Testing,
If it is Test Automation / Automated Testing, if you provide the correct logic then test tool
can provide correct output.)
[Link] change requests during software maintenance takes more time.

Automation Testing
Automation testing is the process of testing the software using an automation tools to nd
the [Link] this process, executing the test scripts and generating the results are
performed automatically by automation [Link] is required when we have huge amount of
regression test cases.

Advantage of automation testing :

[Link] human resources


[Link] testing requires fewer people to perform a tedious manual test. To implement
the automation test script,
we need a test automation engineer who can write the test scripts to automate our tests.
[Link] development and delivery
Automated tests can be executed repeatedly and completed rapidly. We do not have to
wait for weeks to execute the tests; few hours are
enough for execution. Switching from manual to automation reduces the waiting time and
boosts developme
[Link] to test on various platforms
[Link] time
Automating the testing process helps the testing team to use less time to validate newly
created features. For instance, in manual testing, there is a
need to write thousand test cases for a calculator application, but automation makes the
process much faster.
6. Cost of the will be reduced
7. Project duration will be reduced.

Disadvantages of automation testing

1. Initial investment – Automated testing requires an initial investment in specialized


software and equipment, which can be costly.
2. Limited to pre-written tests – Automated testing is limited to running pre-written
tests, which may not cover all possible scenarios.
3. Complexity – Automated testing can be complex and dif cult to set up, especially
for large and complex systems.
4. Maintenance – Automated testing requires regular maintenance and updating of
the test scripts, which can be time-consuming.
5. Limited human interaction – Automated testing removes the human element and
intuition in testing, which may result in missing certain edge cases and bugs that a
human tester would have caught.
fi
fi
Ranjeet kendre

Different Automation tools:

1. Loadrunner
2. TesComplete
3. WunRunner
4. Selenium
5. IBM Rational functional Testers
6. HP QTP( QUick Test professional)

What is Selenium?
Selenium is functional and regression automation tool.
Selenium is webbased automationtool/collection of API's (Components).

1. Selenium IDE
2. Selenium RC
3. Selenium Grid
4. Selenium webdriver

Selenium IDE - Plug-in only for refox browser. Record and play back tool.
Selenium RC - Rc Server will interact with browser and execute automating test cases.
Selenium Grid - We can execute test cases remotely.
Selenium Webdriver - Webdriver is an interface which is present in API forms.

Advantages of Selenium webdriver

1. Open Source (Free)


2. Support Multiple language ( Java , Python, C#, Ruby)
3. Support Multiple Browsers ( Chrome, IE, Safari, MS Edge)
4. Support Multiple Operating system ( Window , Linux, MacOS)
5. Support Parallel Testing.
6. Selenium can integrate third party tool - ( TestNG, Maven, Jenkins, AzureDevops,
git,github,Cucumber)

Disadvantage Of Selenium(Limitations)

1. It can not handle window based applications. ( Not Support desktop/window based
application) - AutoIT tool, Sikuli .
2. There is not dedicated support faculty. - N umbers of forms are available.
3. Can not automate captcha.
4. Can not generate good report. - TestNg, Extent report concept
5. Can not support working with excel excel sheet. - Apache Poi
6. Image based testing is supported. (Certain level of testing we can do( Co-ordinate)
fi
Ranjeet kendre

Selenium Web-driver architecture

1. Search context is a super most interface which contains abstract methods


& inherited to webdriver.
2. Web driver is an interface which contains abstract method of search
context and its own abstract methods.
3. All the abstract methods are overridden or implemented in selenium
remote web driver class.
4. Selenium remote web driver-it is class which implements all the abstract
methods of both interface search context and web driver jS, TakeScrshot interface.
5. Selenium remote driver class is extended to browsers such as Firefox,
internet explorer, chrome…..etc.
6. To run application in multiple browsers (C.T) i.e writing test script by
using single browser but run the same script in multiple browser we need
to use runtime polymorphism by using up casting in selenium.
WebDriver driver = new Chrome Driver();
7. Create an object of ChromeDriver class with reference of WebDriver
interface.
Ranjeet kendre

WebDriver explanation

WebDriver driver = new ChromeDriver();


1. After you trigger test cases(Script) the complete selenium code(client) which we have
written will
be converted to JSON format.
2. Generated JSON is sent to browser driver(Server) HTTP protocol.(Each browser
contains a separate browser driver)
3. Browsers driver communicates with its respective browser and executes the command.
4. Browser drivers receives responses back from the real browser and its sends to JSON
response back to the client.

First selenium program

package Demo;

import [Link];
import [Link];
import [Link];

public class FirstProgram {

public static void main(String[] args) {

//Macos
[Link]("[Link]",
"Usersranjeetkendre/Documents/chromedriver");
//Window
//
[Link]("[Link]","C\Installer\chromedr
[Link]");
Ranjeet kendre
WebDriver driver = new ChromeDriver();

// System -- Class name


// Setproperty -- Method name
// Webdrvier - version of selenium
// Chrome - name of the browser
// driver - browser
// [Link] - path of [Link] file

Selenium WebDriver - Browser Commands

1. Get Command

• This method is use to open an application or to enter url in a web page or browser. It
accepts String as parameter and returns void.

[Link](“[Link]

Program
package WebdriverMethods;

import [Link];
import [Link];

public class GetMethods {


Ranjeet kendre

public static void main(String[] args) {


// [Link]
[Link]("[Link]", “/Users/
ranjeetkendre/Documents/chromedriver");
// [Link] 2

WebDriver driver = new ChromeDriver();

// [Link]

[Link]("[Link]

2. Close Command
close();

This method terminates the current browser window operating by WebDriver at the current
time. If the current window is the only window operating by WebDriver, it terminates the
browser as well. This method accepts nothing as parameter and returns void.

package WebdriverMethods;

import [Link];
import [Link];

public class Close {

public static void main(String[] args) throws


InterruptedException {

// Close - to close the current open browser


// 1. GetMethod
// This method is used to open application or to enter
the URL on webbrowser

// [Link]
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
// [Link] 2

WebDriver driver = new ChromeDriver();

// [Link]

[Link]("[Link]
Ranjeet kendre

[Link](5000);

[Link]();

[Link] Title method

In WebDriver, this method fetches the title of the current web page. It accepts no
parameter and returns a [Link] respective command to fetch the title of the current
page can be written as:

package WebdriverMethods;

import [Link];
import [Link];

public class GetTitle {

public static void main(String[] args) {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]
String Title = [Link]();
[Link](Title);
[Link]();
String ExpectedTitle = "Online Shopping site in India:
Shop Online for Mobiles, Books, Watches, Shoes and More -
[Link]";
if ([Link](ExpectedTitle)) {
[Link]("Correct title");
} else {
[Link]("Incorrect title");
}

}
Ranjeet kendre
4. Get Current URL Command

In WebDriver, this method fetches the string representing the Current URL of the current
web page. It accepts nothing as parameter and returns a String [Link] respective
command to fetch the string representing the current URL can be written as

package WebdriverMethods;

import [Link];
import [Link];

public class GetCurrentURL {

public static void main(String[] args) {

[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

String URL = [Link]();

[Link](URL);

if([Link]("[Link]
[Link]("Correct URL");
else {
[Link]("Incorrect URL");
}

[Link]();

5. Get Page Source Command

In WebDriver, this method returns the source code of the current web page loaded on the
current browser. It accepts nothing as parameter and returns a String [Link] respective
command to get the source code of the current web page can be written as:
Ranjeet kendre
Example :

package WebdriverMethods;

import [Link];
import [Link];

public class GetMethods {

public static void main(String[] args) {

// 1. GetMethod
// This method is used to open application or to enter
the URL on webbrowser

// [Link]
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

// [Link] 2

WebDriver driver = new ChromeDriver();

// [Link]

[Link]("[Link]

String PageSource = [Link]();


[Link](PageSource);

}
6. Quit Command

This method terminates all windows operating by WebDriver. It terminates all tabs as well
as the browser itself. It accepts nothing as parameter and returns void.

package WebdriverMethods;

import [Link];
import [Link];
import [Link];

public class Quite {

public static void main(String[] args) throws


InterruptedException {
Ranjeet kendre
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]
web/[Link]/auth/login");

[Link]().window().maximize();

[Link](5000);

[Link]([Link]("//
a[contains(text(),'OrangeHRM, Inc')]")).click();

[Link](5000);

[Link]();

7. WebDriver - Navigation Commands

WebDriver provides some basic Browser Navigation Commands that allows the browser to
move backwards or forwards in the browser's history.

Just like the browser methods provided by WebDriver, we can also access the navigation
methods provided by WebDriver by typing [Link]() in the Eclipse panel.

1. Navigate To Command
2. Forward Command
3. Forward Command
4. Refresh Command

Example :
package WebdriverMethods;

import [Link];
import [Link];

public class Navigate {

public static void main(String[] args) throws


InterruptedException {
Ranjeet kendre

[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link](4000);

[Link]().window().maximize();

[Link]().to("[Link]

[Link](4000);

String Title = [Link]();


[Link](Title);

[Link]().to("[Link]
[Link]/web/[Link]/auth/login");

String Title1 = [Link]();

[Link](Title1);

[Link]().back();

[Link](4000);

[Link]().forward();

[Link](4000);
Ranjeet kendre

[Link]().refresh();

[Link](5000);

[Link]();
}
}

8. maximize method
This method is used to maximize the browser
Example :
package WebdriverMethods;

import [Link];
import [Link];

public class Maximize {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link](4000);

[Link]().window().maximize();

[Link]("[Link]

[Link]();

9. setSize() method

• This method is use to change size of the browser which accepts dimensions arguments
setSize() method can’t accept directly the width and height of the browser. This method
accept only dimension arguments.
Ranjeet kendre

• Before using setSize() method we need to create the object of the dimension class and then
pass the width and height of the browser in the constructor of the dimension class
Dimension class present in the selenium
Type dime----use control+space
To enter width and height value is the browser resolution or picsal value

package WebdriverMethods;
import [Link];
import [Link];
import [Link];

public class SetSize {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]
web/[Link]/auth/login");

[Link]().window().maximize();

[Link](5000);
Ranjeet kendre
//W H
Dimension D1 = new Dimension(800,700);

[Link]().window().setSize(D1);
[Link](10000);
[Link]([Link]().window().getSize());
[Link]();
}
}

10. getSize method

• check the browser size immediate open of browser


to check the size to call the printing statement and inside the printing statement to call the
function [Link]().window().getSize()
Return dimension arguments in terms of width and height

[Link]

• This method is use to change position of the browser which accept point argument Before
using setPosition() method we need to create the object of the point class and then pass the x
and y coordinate of the browser in the
constructor of the point class .Type poi----use control+space

• Example
package WebdriverMethods;

import [Link];
import [Link];
import [Link];

public class SetPosition {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link](4000);

[Link]().window().maximize();

[Link]("[Link]
// W H
Point P1 = new Point(500,300);
Ranjeet kendre

[Link]().window().setPosition(P1);

[Link](4000);
[Link]([Link]().window().getPosition());
[Link]();
}
}

12..getPosition()

• check the position of the browser in terms of x and y coordinates to get this coordinate so to
call the printing statement and inside the
printing statement to call the function [Link]().window().getPosition()
Return point arguments in terms of x and y arguments
Ranjeet kendre

Locators :
Locators are the way to identify an HTML element on a webpage.

To identify an element present in webpage we need to use ‘findElement’

method which is present in web driver.


Locators Types :

[Link]
[Link]
[Link]
[Link] Name
[Link]
[Link] link Text
[Link] Selector
[Link]

What is xpath?

It Is a Syntax or Language for Finding any Element on the Web Page Using Xml
Pathe [Link] Is a Selenium Technique To Navigate Through a Page's
HTML Structure.

Xpath Is Used To Find the Location of any Element on a Webpage Using HTML
DOM [Link] Is a Address of Element

Types of Xpath

1. Absolute Xpath
2. Relative XPath
1. Xpath by Attributes
2. Xpath by Text
3. Xpath by Contains
4. Xpath by Index

Absolute Xpath :

1. Absolute Xpath Starts From Root Node


2. AX Starts With (/)Forward Slash
3. In AX We Used Only Tag Names
Ranjeet kendre

Example :

package Locaters;

import [Link];
import [Link];
import [Link];

public class Absolutexpath1 {

public static void main(String[] args) {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]().window().maximize();

[Link]([Link]("/html/body/div/div/div/div/
div/div/div[2]/div/div/form/div/div/input")).sendKeys("RRR");

[Link]([Link]("/html/body/div/div/div/div/
div/div/div[2]/div/div/form/div/div[2]/div/
input")).sendKeys("1234");
Ranjeet kendre

Example 2
package Locaters;

import [Link];
import [Link];
import [Link];
import [Link];

public class AbsoluteXpath2 {

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


{

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]().window().maximize();
//
// [Link]([Link]("/html/body/div/div/div[2]/form/
div[3]/div/div/div/input")).sendKeys("Rahul@[Link]");
//
// [Link]([Link]("/html/body/div/div/div[2]/form/
div[4]/div/div/div/input")).sendKeys("3445675");
Ranjeet kendre
[Link]([Link]("loginBtn")).click();

[Link]();

WebElement El=[Link]([Link]("//
button[@id=\"loginBtn\"]"));
[Link]([Link]());

}
}

Relative Xpath

1. Xpath by Attribute

Synatx: //Tagname[@Attributename="Attribute Value"]

[Link]([Link](“//Input[@Id=\”Dest\"]"));

Example :

package Locaters;

import [Link];
import [Link];
import [Link];

public class XPathbyAttribute {


Ranjeet kendre

public static void main(String[] args) throws


InterruptedException {

// Syntax - //[Link]([Link]("Xpath
expression")
//Step 1 :
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

//Step 2

WebDriver driver =new ChromeDriver();

//Step 3

[Link]().window().maximize();

[Link]("[Link]

[Link]([Link]("//input[@class=\"inputtext
_55r1 _6luy\"]")).sendKeys("rahul@[Link]");

[Link]([Link]("//
input[@id=\"email\"]")).sendKeys("Rahul");

[Link]([Link]("//
input[@name=\"pass\"]")).sendKeys("123456789");

[Link]([Link]("//
input[@id=\"pass\"]")).sendKeys("1234");

[Link]([Link]("//
div[@class=\"_9lsa\"]")).click();//NoSuchElementException

[Link]([Link]("//
button[@type=\"submit\"]")).click();

[Link](3000);

//[Link](5000);

[Link]();
//
}

}
Ranjeet kendre

2.

2. Xpath by Text

Syntax - //Tagname[Text()='text Value']

Example - //[Link]([Link]("//Button[Text()='Log in’]")).Click();

package Locaters;

import [Link];
import [Link];
import [Link];

public class XpathByText {

public static void main(String[] args) {


// Syntax - //[Link]([Link]("Xpath expression")
//Step 1 :
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

//Step 2

WebDriver driver =new ChromeDriver();

//Step 3
Ranjeet kendre

[Link]().window().maximize();

[Link]("[Link]

[Link]([Link]("//input[@class=\"inputtext
_55r1 _6luy\"]")).sendKeys("rahul@[Link]");

[Link]([Link]("//
input[@id=\"pass\"]")).sendKeys("1234");
//Xpath by text
//[Link]([Link]("//button[text()=\"Log
in\"]")).click();

// [Link]([Link]("//a[text()=\"Forgotten
password?\"]")).click();

//String S1 ="Facebook helps you connect and share with


the people in your life.";
[Link]([Link]("//a[text()=\"Create a
Page\"]")).click();

}
Ranjeet kendre
3. Xpath by Contains

Syntax - //Tagname[Contains(Text(),'Textvalue')]

Example : [Link]([Link](“//
Button[Contains(Text(),’Log’)]")).Click();

package Locaters;

import [Link];
import [Link];
import [Link];

public class Xpathbycontains {

public static void main(String[] args) throws


InterruptedException {

// Syntax - //[Link]([Link]("Xpath
expression")

//Step 1 :

[Link]("[Link]",
"/Users/ranjeetkendre/Documents/chromedriver");

//Step 2

WebDriver driver =new ChromeDriver();

//Step 3

[Link]().window().maximize();

[Link]("[Link]

[Link]([Link]("//
input[@class=\"inputtext _55r1
_6luy\"]")).sendKeys("rahul@[Link]");

[Link]([Link]("//
input[@id=\"pass\"]")).sendKeys("1234");
//Xpath by text
//[Link]([Link]("//
button[text()=\"Log in\"]")).click();

// [Link]([Link]("//
a[text()=\"Forgotten password?\"]")).click();
Ranjeet kendre

// String S1 ="Facebook helps you connect and share


with the people in your life.";

// [Link]([Link]("//a[text()=\"Create
a Page\"]")).click();

// [Link]([Link]("//
button[contains(text(),'Log in')]")).click();

// [Link]([Link]("//
button[contains(text(),'Log')]")).click();

[Link]([Link]("//
a[contains(text(),'Fo')]")).click();

[Link]([Link]("//
h2[contains(text(),'Facebook helps you connect and share with
the people in your life.')]"));

[Link](4000);

[Link]();
}

}
Ranjeet kendre
4. xpath by index
Syntax : (Xpath Expression)[index number]
Example : //[Link]([Link](“(//li[@data-
id=\"462\"])[2]"))

package Locaters;

import [Link];
import [Link];
import [Link];

public class Xpathbyindex {

public static void main(String[] args) throws


InterruptedException {

// Syntax - //[Link]([Link]("Xpath
expression")

//Step 1 :

[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

//Step 2

WebDriver driver =new ChromeDriver();

//Step 3

[Link]().window().maximize();

[Link]("[Link]

[Link]([Link]("(//a[@class=\"nav-a
\"])[8]")).click();

[Link](4000);

[Link]();
}

}
Ranjeet kendre

Dynamic Xpath

package Locaters;

import [Link];

import [Link];

import [Link];

public class DynamicXpath {

public static void main(String[] args) {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();


//Dynamic IDs

//[Link]("[Link]
[Link]("[Link]
[Link]().window().maximize();
//1 Containsbyattribute
Ranjeet kendre
//[Link]([Link]("//button[contains(@id,
\"u_0_5_\")]")).click();

//2. starts-with
//id="u_0_5_y9"

[Link]([Link]("//button[starts-
with(@id,'u_0_5_')]")).click();

//[Link]-with
//[Link]([Link]("//button[ends-
with(@id,'u_0_5_')]")).click();

2. By ID
driver. ndelemet([Link](‘Attributevalue');

Here an object is accessed with the help of IDs. In this case, it is the ID of the text box.
Values are entered into the text box using the sendkeys method with the help of
ID(cdensity).

Example
fi
Ranjeet kendre
package Locaters;

import [Link];
import [Link];
import [Link];

public class ID {

public static void main(String[] args) {


// Step 1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

// Step2

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]().window().maximize();

// ID

[Link]([Link]("email")).sendKeys("Rahul");

// synatx
// [Link]([Link]("Id value"));

[Link]([Link]("pass")).sendKeys("qwerty");

// [Link]([Link]("u_0_5_hE")).click();

[Link]([Link]("//button[contains(@id,
\"u_0_5\")]")).click();
}}

Example 2:
package Locaters;

import [Link];
import [Link];
import [Link];

public class ID1 {

public static void main(String[] args) throws


InterruptedException {
Ranjeet kendre

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

// Step2

WebDriver driver = new ChromeDriver();

[Link]("[Link]
test-login/");

[Link]().window().maximize();

// ID

// [Link]([Link]("email")).sendKeys("Rahul");

// synatx
// [Link]([Link]("Id value"));

[Link]([Link]("username")).sendKeys("student");

[Link]([Link]("password")).sendKeys("Password123");

[Link]([Link]("submit")).click();
Ranjeet kendre
[Link](5000);

[Link]();

[Link] Name
Here an object is accessed with the help of names. In this case, it is the name of the text
box. Values are entered into the text box using the sendkeys method with the help of
ID(cdensity).
syntax - //[Link]("namevalue");
driver. ndElement([Link](“submit_search")).click();
Example
package Locaters;
fi
Ranjeet kendre
import [Link];
import [Link];
import [Link];

public class Name {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

//Step2

WebDriver driver = new ChromeDriver();

[Link]("[Link]
test-login/");

[Link]().window().maximize();

//ID

//[Link]([Link]("email")).sendKeys("Rahul");

//synatx
// [Link]([Link]("Id value"));

[Link]([Link]("username")).sendKeys("student");

[Link]([Link]("password")).sendKeys("Password123");

[Link]([Link]("submit")).click();

[Link](5000);

[Link]();
}

4. By Tag Name
The DOM Tag Name of an element can be used to locate that particular element in the
WebDriver. It is very easy to handle tables with the help of this method. Take a look at the
following code.
driver. ndElement([Link] (“htmltagname”))
package Locaters;

import [Link];
import [Link];
fi
Ranjeet kendre
import [Link];

public class Tagname {

public static void main(String[] args) {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

// Step2

WebDriver driver = new ChromeDriver();

[Link]("[Link]
[Link]");

//[Link]("[Link]

[Link]().window().maximize();

[Link]([Link]("input")).sendKeys("Rohit@123");

}
Ranjeet kendre

5. LinkText

This method helps to locate a link element with matching visible text.
driver. ndElement([Link] (<linktext>))
package Locaters;

import [Link];
import [Link];
import [Link];

public class LinkText {

public static void main(String[] args) throws


InterruptedException {

//Step 1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]().window().maximize();

[Link]([Link]("Forgotten
passwor?")).click();

//[Link]([Link]("Create a
Page")).click();

[Link](5000);

[Link]();

6. By partial link text


This methods helps locate a link element with partial matching visible text.
package Locaters;

import [Link];
fi
Ranjeet kendre

import [Link];
import [Link];

public class Partilalinktext {

public static void main(String[] args) throws


InterruptedException {

//Step 1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]().window().maximize();

//
[Link]([Link]("Forgotten")).click();

[Link]([Link]("Create")).click();

[Link](5000);

[Link]();
Ranjeet kendre
}

7 .Classname
Exanple :
package Locaters;

import [Link];
import [Link];
import [Link];

public class Classname {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]().window().maximize();

[Link]([Link]("phone-
no")).sendKeys("Rohit@1234");

[Link]([Link]("pure-
button")).click();

[Link](5000);

[Link]();

}
Ranjeet kendre

8. CssSelector :

CSS Selectors in Selenium are string patterns used to identify an


element based on a combination of HTML tag, id, class, and
attributes.

//Tag and ID
//[Link] and #ID
//3.[attributename and attributevalue]
//[Link] and [attributename and attributevalue]
//[Link] and attribute value
//[Link]

Example:
package Locators;
import [Link];
import [Link];
import [Link];

public class CSSSelector {

public static void main(String[] args) throws


InterruptedException {

//[Link]
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();
//[Link]("[Link]

[Link]("[Link]

//1.#ID

[Link]([Link]("#email")).sendKeys("qwerty");

[Link]([Link]("#pass")).sendKeys("1234");

[Link]([Link]("#username")).sendKeys("velcoity
@[Link]");

[Link]([Link]("#password")).sendKeys("QWERTY")
;

//[Link] and #ID


Ranjeet kendre

[Link]([Link]("input#username")).sendKeys("vel
coity@[Link]");

[Link]([Link]("input#password")).sendKeys("er2
3t");

//3. [attributename and attributevalue]

[Link]([Link]("[name=\"email\"]")).sendKeys("1
2355");

[Link]([Link]("[name=\"pass\"]")).sendKeys("12
34");

//[Link] and [attributename and attributevalue]

[Link]([Link]("input[name=\"pass\"]")).sendKey
s("13445");

[Link]([Link]("input[name=\"pass\"]")).sendKey
s("1234");

//5. [Link] and attribute value

[Link]([Link]("[Link][id=\"email\"]")
).sendKeys("12345");

[Link]([Link]("[Link][id=\"pass\"]"))
.sendKeys("345");

//6. [Link]

[Link]([Link]("[Link]-
[Link]-form__control.login-
email")).sendKeys("123@[Link]");
[Link]([Link]("[Link]-
[Link]-form__control.login-password.m-
bottom-3")).sendKeys("2345");
[Link](3000);

[Link]();
}

}
Ranjeet kendre
Ranjeet kendre
Webelement Methods

1. Clear Command

package WebelementMethods;
import [Link];
import [Link];
import [Link];

public class Clear1 {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();


[Link]().window().maximize();

[Link]("[Link]

[Link]([Link]("email")).sendKeys("wertyui");

[Link](2000);

[Link]([Link]("email")).clear();

[Link](2000);

[Link]([Link]("email")).sendKeys("ABCD");
[Link]([Link]("pass")).sendKeys("!@#$%^&*");
[Link](2000);

[Link]([Link]("pass")).clear();
[Link](2000);

[Link]([Link](“//
button[@name=\"login\"]")).click();

[Link](5000);

[Link]();
}

}
Ranjeet kendre

Example 2:

import [Link];
import [Link];
import [Link];
import [Link];

public class Clear2 {

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

[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

WebElement qwertyu = [Link]([Link]("email"));

[Link]("234567");
[Link](2000);
[Link]();
[Link](2000);
[Link]("Rahul");

WebElement werty = [Link]([Link]("pass"));


[Link]("23456789");
[Link](2000);
Ranjeet kendre
[Link]();
[Link](2000);
[Link]("3456789");

[Link](2000);

[Link]();
}

2. Sendkeys and Click

package WebelementMethods;

import [Link];
import [Link];
import [Link];

public class SendkeyandClick {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
Ranjeet kendre

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

//Sendkeys
[Link]([Link]("email")).sendKeys("RTEST");
[Link]([Link]("pass")).sendKeys("23456");

//Click
[Link]([Link]("//
button[@name=\"login\"]")).click();
[Link](4000);

[Link]();
}

}
Ranjeet kendre
4. IsDisplayed Command
package WebelementMethods;

import [Link];
import [Link];
import [Link];
import [Link];

public class IsDisplayed {

public static void main(String[] args) {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
returnUrl=%2F");

WebElement Input=[Link]([Link]("//
input[@id=\"small-searchterms\"]"));

[Link]([Link]());

[Link]();
}

}
Ranjeet kendre

5. IsEnabled Command
package WebelementMethods;

import [Link];
import [Link];
import [Link];

public class Isenabled {

public static void main(String[] args) {

// TODO Auto-generated method stub


[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

Boolean B1=[Link]([Link]("//
button[@name=\"login\"]")).isEnabled();

[Link](B1);
}

}
Ranjeet kendre
6. IsSelected Command

package WebelementMethods;

import [Link];
import [Link];
import [Link];

public class isSelected {

public static void main(String[] args) throws


InterruptedException {

// 1. Step
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

// 2. Step
WebDriver driver = new ChromeDriver();

// 3. Step

[Link]().window().maximize();

[Link]("[Link]

[Link]([Link]("//a[contains(text(),'Create
new account')]")).click();

[Link](3000);

[Link]([Link]("//
input[@type=\"radio\"]")).click();

boolean Button = [Link]([Link]("//


input[@type=\"radio\"]")).isSelected();

[Link](Button);

Boolean B1 = [Link]([Link]("(//
input[@type=\"radio\"])[2]")).isSelected();

[Link](B1);

[Link]([Link]("(//input[@type=\"radio\"])
[2]")).click();

Boolean B2 = [Link]([Link]("(//
input[@type=\"radio\"])[2]")).isSelected();
[Link](B2);
[Link]();
Ranjeet kendre

8. GetText Command

package WebelementMethods;

import [Link];
import [Link];
import [Link];

public class GetText {

public static void main(String[] args) {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();
Ranjeet kendre

[Link]("[Link]

String ExpectedText ="Facebook helps you connect and


share with the people in your life.";

String EXPText ="Create a Page";


String Actualtext=[Link]([Link]("//
h2[contains(text(),'Facebook helps you')]")).getText();

if([Link](Actualtext)) {
[Link]("Correct Text");
}
else {
[Link]("incorrect Text");

String Text= [Link]([Link]("//


a[@class=\"_8esh\"]")).getText();
if([Link](Text))
[Link]("Correct text");
else
[Link]("Incorrect text");

[Link]();
}

}
Ranjeet kendre

9. GetTagName Command
1. WebElement element = driver. ndElement([Link]("SubmitButton"));
2. String tagName = [Link]();
3.
4. //Or can be written as
5.
6. String tagName = driver. ndElement([Link](“SubmitButton")).getTagName();

10. getCssValue Command


1. [Link]();

11. getAttribute Command


1. WebElement element = driver. ndElement([Link]("SubmitButton"));
2. String attValue = [Link]("id"); //This will return "SubmitButton"

13. getLocation Command


1. WebElement element = driver. ndElement([Link]("SubmitButton"));
2. Point point = [Link]();
3. [Link]("X cordinate : " + point.x + "Y cordinate: " + point.y);
fi
fi
fi
fi
Ranjeet kendre
List Box

• How to handle list box using selenium?


Step1
Identify listbox which need to be handled and store it in a reference variable
Step2
Create an object of select class which accept webelement arguments
Step3
Use select class method to select options
1. selectByValue(String value)
2. selectByVisibleText(String text)
3. sslectByIndex(int Index)
In the select class all the function are non-static so we have to create the object of select
class.

• In the select class inbuild functions are available but here to be select class know the which
element to perform action. So for that reasons we have provide input to the select class it is
webelement type object.

• Then to call select class functions in objectname. selectclassfunction in the select class
selectByValue function input field is String.

• Date, month and year in that can’t handle at a time we have handle
separately by creating three object of select class.
List of methods present in select class
1. selectByValue(String value)
2. selectByVisibleText(String text)
3. sslectByIndex(int Index)
4. getOptions()-List<WebElement>
5. isMultiple()-boolean
6. getFirstSelectedOption()-WebElement
7. getAllSelectedOptions()-List<WebElement>

• Example

package ListBox;

import [Link];
import [Link];
import [Link];

public class ListBox1 {

public static void main(String[] args) throws


InterruptedException {
//Without select classs
Ranjeet kendre
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]().window().maximize();

[Link]([Link]("//a[contains(text(),'Create
new account')]")).click();

[Link](3000);
[Link]([Link]("//input[@class=\"inputtext
_58mg _5dba _2ph-\"]")).sendKeys("Rohit");
[Link]([Link]("//
input[@name=\"lastname\"]")).sendKeys("Patil");
[Link]([Link]("//
input[@name=\"reg_email__\"]")).sendKeys("2345678");

[Link]([Link]("//input[@type=\"password\"
and @class=\"inputtext _58mg _5dba _2ph-\"]")).sendKeys("wert");

[Link]([Link]("day")).click();
[Link]([Link]("//
option[@value=\"6\"]")).click();
// [Link](3000);

[Link]([Link]("month")).click();
[Link]([Link]("//
option[contains(text(),'Mar')]")).click();
// [Link](3000);

[Link]([Link]("year")).click();
[Link]([Link]("//
option[contains(text(),'2022')]")).click();
[Link]([Link]("//
label[@class=\"_58mt\"]")).click();

[Link]();

}
Ranjeet kendre

Example 2
package ListBox;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ListBox2 {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]().window().maximize();

[Link]([Link]("//a[contains(text(),'Create
new account')]")).click();
Ranjeet kendre

[Link](2000);

[Link]([Link]("//input[@class=\"inputtext
_58mg _5dba _2ph-\"]")).sendKeys("Rohit");
[Link]([Link]("//
input[@name=\"lastname\"]")).sendKeys("Patil");
[Link]([Link]("//
input[@name=\"reg_email__\"]")).sendKeys("2345678");

[Link]([Link]("//input[@type=\"password\"
and @class=\"inputtext _58mg _5dba _2ph-\"]"))
.sendKeys("wert");

WebElement Day = [Link]([Link]("day"));

WebElement Month = [Link]([Link]("month"));

WebElement Year = [Link]([Link]("year"));

//Select byvisible text


//Select Select1 = new Select(Day);

// selectByVisibleText(String text)

//[Link]("4");

//Select Select2 = new Select(Month);

// selectByVisibleText(String text)

//[Link]("Mar");

//Select Select3 = new Select(Year);

// selectByVisibleText(String text)

//[Link]("2022");

//[Link]

// Select Seclect4 = new Select(Day);


// [Link]("7");
//
// Select Seclect5 = new Select(Month);
// [Link]("4");
//
// Select Seclect6 = new Select(Year);
// [Link]("2021");

//[Link]
Ranjeet kendre
Select Seclect7 = new Select(Day);
[Link](4);

Select Seclect8 = new Select(Month);


[Link](1);

Select Select9 = new Select(Year);


[Link](22);

}
Ranjeet kendre

Example 3

package ListBox;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ListBox3 {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]().window().maximize();

[Link]([Link]("//a[contains(text(),'Create
new account')]")).click();

[Link](5000);

[Link]([Link]("//input[@class=\"inputtext
_58mg _5dba _2ph-\"]")).sendKeys("Rohit");
[Link]([Link]("//
input[@name=\"lastname\"]")).sendKeys("Patil");
[Link]([Link]("//
input[@name=\"reg_email__\"]")).sendKeys("2345678");

[Link]([Link]("//input[@type=\"password\"
and @class=\"inputtext _58mg _5dba _2ph-\"]"))
.sendKeys("wert");

WebElement Day = [Link]([Link]("//


select[@id=\"day\"]"));
WebElement Month = [Link]([Link]("//
select[@id=\"month\"]"));
WebElement Year = [Link]([Link]("//
select[@id=\"year\"]"));

String DOB = "23/Mar/2019";


Ranjeet kendre

String[] Date = [Link]("/");


//0 - 23
//1 - 4
//2 - 2019

ListBox(Day,Date[0]);
ListBox(Month,Date[1]);
ListBox(Year,Date[2]);

// ListBox(Day,"22");
// ListBox(Month,"3");
// ListBox(Year, "2019");

public static void ListBox(WebElement element, String Text) {

Select Select1 = new Select(element);


[Link](Text);
}
}
Ranjeet kendre

Example 4

package ListBox;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ListBox4 {

public static void main(String[] args) throws


InterruptedException {

// Step 1

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

// Step 2

WebDriver driver = new ChromeDriver();

// ChromeDriver driver1 =new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

[Link]([Link]("//a[contains(text(),'Create
new account')]")).click();

[Link](5000);

[Link]([Link]("//input[@class=\"inputtext
_58mg _5dba _2ph-\"]")).sendKeys("Rohit");
[Link]([Link]("//
input[@name=\"lastname\"]")).sendKeys("Patil");
[Link]([Link]("//
input[@name=\"reg_email__\"]")).sendKeys("2345678");

[Link]([Link]("//input[@type=\"password\"
and @class=\"inputtext _58mg _5dba _2ph-\"]"))
.sendKeys("wert");

WebElement Day = [Link]([Link]("//


select[@id=\"day\"]"));
Ranjeet kendre
WebElement Month = [Link]([Link]("//
select[@id=\"month\"]"));
WebElement Year = [Link]([Link]("//
select[@id=\"year\"]"));

// Question1
// How will u get the total no size of list

Select S1 = new Select(Day);


List<WebElement>LL=[Link]([Link]("//
select[@id=\"day\"]//option"));
List<WebElement> ListDay = [Link]();
[Link]("Totaldays -->" + [Link]());
[Link]("Totaldays -->" + [Link]());

// Question 2
// How will u print all the values
// 0 ;0<31
// 1<31
for (int i = 0; i < [Link](); i++) {

String DayValues = [Link](i).getText();


// 1 = [Link]();
[Link](DayValues); // 1 2
// Question 3
// How will u select specifix values from the
dropdown
if ([Link]("14")) {// 14.14 [Link] 14
[Link](i).click();
}
}
//select month
Select S2 = new Select(Month);

List<WebElement> Monthvalues=[Link]();
[Link]("Total month-->"+[Link]());

[Link]();

for(int j=0;j<[Link]();j++) {

String Months=[Link](j).getText();
[Link](Months);

if([Link]("May")) {

[Link](j).click();
}
}
// [Link]();
}
Ranjeet kendre
}
Ranjeet kendre

Example 5

package ListBox;

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class ListBox5 {

@SuppressWarnings("deprecation")
public static void main(String[] args) throws
InterruptedException {

//Step -1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver =new ChromeDriver();

[Link]().window().maximize();
[Link]("[Link]
[Link]().timeouts().implicitlyWait(20,
[Link]);
[Link](4000);

[Link]([Link]("src")).sendKeys("Pune");
// [Link](3000);

List<WebElement> City= [Link]([Link]("//


text[@class=\"placeHolderMainText\"]"));
[Link](3000);
[Link]("Total Count :"+[Link]());

for(int i=0;i<[Link]();i++) {

[Link](i).getText();
[Link]([Link](i).getText());
if([Link](i).getText().equals("Wakad")){
// [Link]([Link](i).getText());
// [Link](2000);
// [Link](i).click();
// break;
}
}
Ranjeet kendre

[Link]();
[Link]([Link]("dest")).sendKeys("Mumbai");
[Link](3000);
List<WebElement> DestCity =
[Link]([Link]("//
text[@class=\"placeHolderMainText\"]"));

[Link]("Total City Count :"+[Link]());


for(int i=0;i<[Link]();i++) {

[Link](i).getText();
[Link]([Link](i).getText());
if([Link](i).getText().equals("Vashi")){
[Link]([Link](i).getText());
[Link](2000);
[Link](i).click();
break;
}

[Link]([Link]("//td[@class=\"current
day\"]")).click();
[Link]([Link]("search_btn")).click();
}
Ranjeet kendre
}

Example 6

package ListBox;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class Listbox6 {

static WebDriver driver;

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

// Step 2

driver = new ChromeDriver();

// ChromeDriver driver1 =new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
[Link]([Link]("//a[contains(text(),'Create
new account')]")).click();
[Link](4000);
[Link]([Link]("//input[@class=\"inputtext
_58mg _5dba _2ph-\"]")).sendKeys("Rohit");
[Link]([Link]("//
input[@name=\"lastname\"]")).sendKeys("Patil");
[Link]([Link]("//
input[@name=\"reg_email__\"]")).sendKeys("2345678");

[Link]([Link]("//input[@type=\"password\"
and @class=\"inputtext _58mg _5dba _2ph-\"]"))
.sendKeys("wert");

String Day = "//select[@id=\"day\"]/option";


String Month = "//select[@id=\"month\"]/option";
String Year = "//select[@id=\"year\"]/option";
Ranjeet kendre
String DOB = "15-Jun-2020";
String date[] = [Link]("-");
// date[0]=15
// date[1]=Jun
// date[2]=2020
Selectdropdown(Day, date[0]);
Selectdropdown(Month, date[1]);
Selectdropdown(Year, date[2]);
}

public static void Selectdropdown(String element, String


values) {

List<WebElement> V1 =
[Link]([Link](element));
[Link](V1);
[Link]([Link]());

for (int i = 0; i < [Link](); i++) {

[Link]([Link](i).getText());

if ([Link](i).getText().equals(values)) {
[Link](i).click();
}}}}
Ranjeet kendre

Parameterization

What is Meant by in Selenium?


The process of parameterizing test scripts in order to pass numerous data to the
application during runtime is called [Link] is a strategy of execution
which automatically runs test cases multiple times using di erent values. The
concept achieved by parameterizing the test scripts is called Data Driven Testing.

How to fetch data from Excel sheet? Steps

1. To fetch data from excel sheet 1st we need to con gure Apache Poi Jar file in
to our project.
[Link] an object of “FileInputStream” class with excel sheet path as an input
[Link] open an excel sheet we need to use a static method i.e. create() which is
present in “WorkbookFactory” class
[Link] open specific sheet in an excel we need to use getSheet() method
[Link] identify specific row in a sheet we need to use getRow() method
6To identify specific cell in a row we need to use getCell() method
[Link] fetch string type of information we need to call getStringCellValue()
method or To fetch numeric type of information we need to call
getNumericCellValue() method—Return type of getNumericCellValue- double
orTo fetch boolean type of information we need to call getBooleanCellValue()
method

Examples 1
package Parameterization;

import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ReadData1 {

public static void main(String[] args) throws


EncryptedDocumentException, IOException, InterruptedException {
fi
ff
Ranjeet kendre

//To fetch String data from Excel sheet


FileInputStream file = new FileInputStream("/Users/
ranjeetkendre/Desktop/[Link]");

String data =
[Link](file).getSheet("Sheet1").getRow(0).getCell(
0).getStringCellValue();

[Link](data);
FileInputStream file1 = new FileInputStream("/Users/
ranjeetkendre/Downloads/[Link]");
XSSFWorkbook workbook = new XSSFWorkbook(file1);

String
Data1=[Link](0).getRow(0).getCell(0).getStringCellVal
ue();

[Link](Data1);

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]().window().maximize();

[Link]([Link]("email")).sendKeys(data);

[Link]([Link]("pass")).sendKeys(Data1);

[Link]([Link]("//button[@class=\"_42ft
_4jy0 _6lth _4jy6 _4jy1 selected _51sy\"]")).click();

[Link](4000);

[Link]();

}
Ranjeet kendre

Example 2

package Parameterization;

import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ReadData2 {

public static void main(String[] args) throws


EncryptedDocumentException, IOException, InterruptedException {

// To fetch String data from Excel sheet


FileInputStream file = new FileInputStream("/Users/
ranjeetkendre/Downloads/[Link]");
Ranjeet kendre

String data =
[Link](file).getSheet("Sheet1").getRow(0).getCell(
0).getStringCellValue();

[Link](data);

FileInputStream file1 = new FileInputStream("/Users/


ranjeetkendre/Downloads/[Link]");

String data1 =
[Link](file1).getSheet("Sheet1").getRow(1).getCell
(0).getStringCellValue();

[Link](data1);

FileInputStream file2 = new FileInputStream("/Users/


ranjeetkendre/Downloads/[Link]");

String data2 =
[Link](file2).getSheet("Sheet1").getRow(1).getCell
(1).getStringCellValue();

[Link](data2);

// FileInputStream file1 = new FileInputStream("/Users/


ranjeetkendre/Downloads/[Link]");
// XSSFWorkbook workbook = new XSSFWorkbook(file1);
//
// String
Data1=[Link](0).getRow(0).getCell(0).getStringCellVal
ue();
//
// [Link](Data1);

FileInputStream file3 = new FileInputStream("/Users/


ranjeetkendre/Downloads/[Link]");

double data3 =
[Link](file3).getSheet("Sheet2").getRow(0).getCell
(0).getNumericCellValue();

[Link](data3);

FileInputStream file4 = new FileInputStream("/Users/


ranjeetkendre/Downloads/[Link]");

double data4 =
[Link](file4).getSheet("Sheet3").getRow(0).getCell
(0).getNumericCellValue();

[Link](data4);
Ranjeet kendre

}}

Example 3

package Parameterization;

import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ReadData3 {

public static void main(String[] args) throws


EncryptedDocumentException, IOException, InterruptedException {
Ranjeet kendre
String file = "./TestData/[Link]";
FileInputStream file1 = new FileInputStream(file);
XSSFWorkbook work = new XSSFWorkbook(file1);

XSSFSheet Sheet = [Link](3);

int Rows = [Link]();


[Link](Rows);
int Cols = [Link](1).getLastCellNum();
[Link](Cols);

for(int R=0 ;R<=Rows; R++) {

XSSFRow row = [Link](R);

for(int C=0 ;C<Cols;C++) {

XSSFCell cell=[Link](C);

switch([Link]()){

case STRING:

[Link]([Link]());
break;
case NUMERIC:

[Link]([Link]());
break;
case BOOLEAN:

[Link]([Link]());
break;
}
[Link](" || ");
}
[Link]();
}

}
Ranjeet kendre

Screenshot

How to take screenshot using selenium webdriver

• 1) To take screenshot using selenium webdriver we need to type cast driver object in
to TakesScreenshot interface. (down casting)
Ex. ((TakeScreenshot)driver) 2) Then we need to call the function i.e.
getScreenshotsAs(), here we need to pass the input/argument “[Link]”
3) This method will return object of type File Ex.
File source=((TakesScreenshot)driver).getScreenshotAs([Link])
4) When this statement will execute it will take screenshot, but screenshot
available inside/local memory.
5) To store screenshot in local driver, we need to call a method i.e. copy( , )
which is present inside FileHandler class.
6) So this function will accept 2 parameter i.e. 1. source and 2. destination
Ex. [Link](source,destination)

Example 1.

package Screenshots;

import [Link];
Ranjeet kendre

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class Screesnhots1 {

public static void main(String[] args) throws IOException {

//Step 1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

//Step 2
WebDriver driver =new ChromeDriver();

//Step 3
[Link]().window().maximize();
[Link]("[Link]

//take screenshot and copy object


Ranjeet kendre
File source =
((TakesScreenshot)driver).getScreenshotAs([Link]);
//[Link](source);

File Destination = new File("/Users/ranjeetkendre/


Desktop/11March/[Link]");

[Link](source,Destination);
[Link]();

Example 2

package Screenshots;

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class Screenshots2Randomnames {

public static void main(String[] args) throws IOException {

[Link]("[Link]", "/Users/
ranjeetkendre/Downloads/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

//Take screenshot and copy into object

File Source =((TakesScreenshot)


driver).getScreenshotAs([Link]);

String Random = [Link](5);


Ranjeet kendre
String Filename = "Facebook";

File Dest = new File("/Users/ranjeetkendre/


Desktop/23July/"+Filename+""+Random+".jpg");

[Link](Source, Dest);

[Link]();

}
Ranjeet kendre

Example 3
package Screenshots;

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class Screenshots3Projectfolder {

public static void main(String[] args) throws IOException {

[Link]("[Link]", "/Users/
ranjeetkendre/Downloads/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

//Take screenshot and copy into object

File Source =((TakesScreenshot)


driver).getScreenshotAs([Link]);

String Random = [Link](5);

String Filename = "Facebook";

File Dest = new File("/Users/ranjeetkendre/Desktop/


eclipse-workspace/TesNgTutorial/23July_Automation/
Screenshot/"+Filename+""+Random+".png");
// String Dest1 = new File("[Link]")
+"Screenshot/"+Filename+""+Random+".png";

[Link](Source, Dest);

[Link]();

}}
Ranjeet kendre

How to handle iFrame in Selenium

Difference between frame and iframe in Selenium

The frame enables a developer to split the screen horizontally or vertically by using the
frameset tag

The iframes are mainly used to insert content from external sources. For example, an
advertisement displayed on a web page. They can oat within the webpage, which means
one can position an iframe at a speci c position on a web page.
Displaying webpage as a part of another webpage is known as iframe.

How to identify a Frame on a Page?


For a browser to automatically start interacting with the web page, the browser needs to
identify the elements under the frame for Selenium testing. It is possible to identify the
iframes on a web page in two ways:
• Right-click on the speci c element and check all the options. If you nd an option
like This Frame, view Frame source or Reload Frame, the page includes
frames. Consider the image below as an example.
fi
fi
fl
fi
Ranjeet kendre

Q.1. How to handle iframe using selenium webdriver

1. To handle iframe using selenium webdriver, we need to switch selenium focus from main page
to frame by suing Syntax- [Link]().frame()
[Link] can switch to iframe using 4 ways i.e. / in that frame we can pass different arguments/
input like
[Link] id
[Link] class
[Link] index
[Link] webelement

[Link] actions performed on components present in iframe, selenium will not navigate by
default to main page.
[Link] navigate from iframe to main page we need to use method like
[Link]()
[Link]()
[Link] we use [Link]() then it will navigate from child frame to immediate
child frame.
[Link] we use [Link]() then it will be navigate from any child to main
page.

Example

package Iframe;

import [Link];
import [Link];
import [Link];

public class IFrame1 {

public static void main(String[] args) throws


InterruptedException {
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]
filename=tryjs_myfirst");

[Link]().window().maximize();

[Link]().frame("iframeResult");

[Link](3000);
Ranjeet kendre
[Link]([Link]("//
button[@type=\"button\"]")).click();
//NoSuchElementException:

[Link]().defaultContent();

[Link]([Link]("//
a[@id=\"tryhome\"]")).click();

//[Link]();
}

Example 2

package Iframe;

import [Link];
import [Link];
import [Link];

public class IFrame2 {

public static void main(String[] args) throws


InterruptedException {
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
Ranjeet kendre
WebDriver driver = new ChromeDriver();

[Link]("[Link]
[Link]");

[Link]().window().maximize();

[Link]().frame("singleframe");

[Link]([Link]("//
input[@type=\"text\"]")).sendKeys("Automation");
//NoSuchElementException

[Link]().defaultContent();

[Link]([Link]("//
a[contains(text(),'Home')]")).click();
}

Example 3

package Iframe;

import [Link];
Ranjeet kendre

import [Link];
import [Link];
import [Link];

public class IFrame3 {

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

[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]("[Link]

[Link]().window().maximize();

[Link]([Link]("//a[contains(text(),'Iframe with in an
Iframe')]")).click();

WebElement Outerframe = [Link]([Link]("//


div[@id=\"Multiple\"]//iframe"));

[Link]().frame(Outerframe);

String text = [Link]([Link]("//


h5[contains(text(),'Nested iFrames')]")).getText();

[Link](text);
Ranjeet kendre

WebElement Innerframe = [Link]([Link]("/html/body/


section/div/div/iframe"));

[Link]().frame(Innerframe);// selenium focous - ineer frame

[Link]([Link]("//
input[@type=\"text\"]")).sendKeys("Welcome");

// [Link]().parentFrame(); //
//
// [Link]("Oterframe-->" + text);

[Link]().defaultContent();

[Link]([Link]("//
a[contains(text(),'WebTable')]")).click();

[Link]("Execution completed");

[Link]();
}

Example 4

package Iframe;

import [Link];
import [Link];
import [Link];

public class IFrame4 {

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


[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");

WebDriver driver = new ChromeDriver();


Ranjeet kendre

[Link]("[Link]
filename=tryhtml_iframe_height_width");

[Link]().window().maximize();

[Link]().frame("iframeResult");

[Link](3000);

[Link]().frame(0);

String Text=[Link]([Link]("//h1[contains(text(),'This page is


displayed in an iframe')]")).getText();

[Link](Text);

[Link]().parentFrame();

String Text1=[Link]([Link]("//p[contains(text(),'You can use the


height and width attributes to specify the size of the iframe:')]")).getText();

[Link](Text1);
[Link]().defaultContent();

[Link]([Link]("//a[@onclick=\"openMenu()\"]")).click();

[Link]("Execution completed");
[Link]();
}

}
Ranjeet kendre

Popups

Popups are small or separate window which will be displayed when we perform action on any
components present in a webpage.
These popups can be handled by selenium directly, but sometimes we may need to use 3rd
party tools to handle these popups.

Types of popups

[Link]-Division Popup
2. JavaScriptAlert popup
[Link] browser Popup
[Link] Popup
[Link] Popup
[Link] Popup

What is Alert in Selenium?

An Alert in Selenium is a small message box which appears on screen to give the user some
information or notification. It notifies the user with some specific information or error, asks for
permission to perform certain tasks and it also provides warning messages as well.

How to handle Alert in Selenium WebDriver

Alert interface provides the below few methods which are widely used in Selenium Webdriver.

1) void dismiss() // To click on the ‘Cancel’ button of the alert.


[Link]().alert().dismiss();

2) void accept() // To click on the ‘OK’ button of the alert.


[Link]().alert().accept();
3) String getText() // To capture the alert message.
[Link]().alert().getText();
4) void sendKeys(String stringToSend) // To send some data to alert box.
[Link]().alert().sendKeys("Text");

Example :

package Popups;

import [Link];
import [Link];
Ranjeet kendre
import [Link];

public class Popup1 {

public static void main(String[] args) {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

[Link]([Link]("//button[@class=\"_2KpZ6l
_2doB4z\”]")).click();

}
}
Ranjeet kendre

Example 2

package Popups;

import [Link];
import [Link];
import [Link];
import [Link];

public class Popup2_JS1 {

public static void main(String[] args) throws


InterruptedException {

// Javascript alert & confirmation popup


[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
javascript_alerts");
Ranjeet kendre

// Alert A1 =new Alert();

[Link]([Link]("//
button[contains(text(),'Click for JS Alert')]")).click();
[Link](3000);
[Link]().alert().accept();
[Link](3000);

Boolean Text = [Link]([Link]("//


p[@id=\"result\"]")).isDisplayed();

[Link](Text);

[Link]();
}

Example 3

package Popups;

import [Link];
import [Link];
import [Link];
import [Link];

public class Popup2_JS2 {

public static void main(String[] args) throws


InterruptedException {

// Javascript alert & confirmation popup


[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
javascript_alerts");

// Alert A1 =new Alert();

[Link]([Link]("//
button[contains(text(),'Click for JS Confirm')]")).click();
[Link](3000);
Ranjeet kendre

// [Link]().alert().accept();

[Link]().alert().dismiss();
[Link](2000);

Boolean Text = [Link]([Link]("//


p[@id=\"result\"]")).isDisplayed();

[Link](Text);

[Link]();
}

Example 4
package Popups;

import [Link];
import [Link];
import [Link];
import [Link];
Ranjeet kendre
public class Popup2_JS3 {

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


{

// Javascript alert & confirmation popup


[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
javascript_alerts");

// Alert A1 =new Alert();

[Link]([Link]("//button[contains(text(),'Click
for JS Prompt')]")).click();
[Link](2000);

Alert Text=[Link]().alert();

[Link]("Alert Message -->"+[Link]());


// [Link](5000);

[Link]().alert().sendKeys("Welcome");
//[Link]("Welcome");
// [Link](5000);
// [Link]();

[Link](2000);
//[Link]();

}
Ranjeet kendre
Example 5

package Popups;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class Popup2_JS4 {

public static void main(String[] args) throws


InterruptedException {

// Javascript alert & confirmation popup


[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

//[Link]("[Link]
[Link]("[Link]

[Link]([Link]("/html/body/div/div/div/div/
following-sibling::div/form/div/div/div/div[2]/
input")).sendKeys("Test");

[Link]([Link]("//
input[@type=\"submit\"]")).click();

String ExpectedalertMsg = "Please enter your password";

Alert alert=[Link]().alert();

String Alertmessage=[Link]();

if([Link](Alertmessage))
[Link]("Correct alert message");
else
[Link]("Incorrect alert message");

[Link](3000);
[Link]();
[Link](3000);
[Link]();
}

}
Ranjeet kendre

Example 6
package Popups;

import [Link];
import [Link];
import [Link];

public class AuthentactionPopup {

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


{

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

//[Link]("[Link]
basic_auth");
[Link]("[Link]
basic_auth");
Ranjeet kendre
// [Link]().alert().sendKeys("admin");
// [Link]().alert().sendKeys("admin");
//
String Text=[Link]([Link]("//
p[contains(text(),'Congratulations! You must have the proper
credentials.')]")).getText();
[Link](Text);
[Link](4000);
[Link]();
}

Example 7
package Popups;

import [Link];
import [Link];
import [Link];

public class PermissionPopup {

public static void main(String[] args) throws


InterruptedException {

ChromeOptions option = new ChromeOptions();

[Link]("--disable-notifications");
// Javascript alert & confirmation popup

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver(option);


Ranjeet kendre
[Link]().window().maximize();

[Link]("[Link]

[Link](2000);

[Link]();

Example 8

package Popups;

import [Link];

import [Link];
import [Link];
import [Link];

public class ChildWindowbrowserPopup {


Ranjeet kendre

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


{

// Javascript alert & confirmation popup


[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

[Link]([Link]("//a[contains(text(),'Open New
Seperate Windows')]")).click();
[Link](4000);
[Link]([Link]("(//
button[contains(text(),'click')])[2]")).click();

String Parentwindow=[Link]();
//3A8FCB77546E89250620E30B437142F4
[Link](Parentwindow);

Set<String>Childwindows=[Link]();

for(String Childwindow:Childwindows) {

if(![Link](Childwindow)) {
[Link]().window(Childwindow);
Ranjeet kendre
String Text1=[Link]([Link]("//
h1[contains(text(),'Selenium automates browsers')]")).getText();
[Link](Text1);
[Link]();
}
}
[Link]().window(Parentwindow);

String Text2=[Link]([Link]("//
h1[contains(text(),'Automation Demo Site ')]")).getText();

[Link](Text2);

[Link]();
}

Example 9

package Popups;

import [Link];
import [Link];
Ranjeet kendre
import [Link];

public class WindowPopuporFileUploadpopup {

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

[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

//[Link]("[Link]
[Link]("[Link]

[Link]([Link]("//input[@id=\"file-
upload\"]")).sendKeys("/Users/ranjeetkendre/Downloads/[Link]");
[Link]([Link]("file-submit")).click();

[Link](3000);
[Link]([Link]("//h3[contains(text(),'File
Uploaded!')]")).isDisplayed();

}
}
Ranjeet kendre

What is Action Class in Selenium?

Actions class is an ability provided by Selenium for handling keyboard


and mouse events. In Selenium WebDriver, handling these events
includes operations such as drag and drop, clicking on multiple
elements with the control key, among others. These operations are
performed using the advanced user interactions API.
It mainly consists of Actions that are needed while performing these
operations.

Action class is de ned and invoked using the following syntax:


Actions action = new Actions(driver);
[Link](element).build().perform();

Methods of Action Class


Action class is useful mainly for mouse and keyboard actions. In order
to perform such actions, Selenium provides various methods.

Mouse Actions in Selenium:

doubleClick(): Performs double click on the element


clickAndHold(): Performs long click on the mouse without releasing it
dragAndDrop(): Drags the element from one point and drops to another
moveToElement(): Shifts the mouse pointer to the center of the element
contextClick(): Performs right-click on the mouse

Keyboard Actions in Selenium:

sendKeys(): Sends a series of keys to the element


keyUp(): Performs key release
keyDown(): Performs keypress without release

Examples :
package ActionsClass;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
fi
Ranjeet kendre
import [Link];

public class MouseOver {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

// Step 2

WebDriver driver = new ChromeDriver();

// ChromeDriver driver1 =new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

WebElement Account = [Link]([Link]("//


span[contains(text(),'Account & Lists')]"));

Actions act = new Actions(driver);

[Link](Account).build().perform();

[Link]([Link]("(//
span[contains(text(),'Sign in') and @class=\"nav-action-inner\"])
[1]")).click();

[Link]([Link]("ap_email")).sendKeys("velocity@[Link]
");

[Link]([Link]("continue")).click();

[Link]([Link]("ap_password")).sendKeys("qwertyu");

[Link]([Link]("signInSubmit")).click();

[Link](3000);

boolean Text = [Link]([Link]("//


span[@class=\"a-list-item\"]")).isDisplayed();

[Link](Text);
}

}
Ranjeet kendre

Example 2

package ActionsClass;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MouseRightClickorContextclick {

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


{

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

// Step 2

WebDriver driver = new ChromeDriver();

// ChromeDriver driver1 =new ChromeDriver();

[Link]().window().maximize();
Ranjeet kendre
[Link]("[Link]
[Link]");

WebElement button = [Link]([Link]("//


span[@class=\"context-menu-one btn btn-neutral\"]"));

Actions act = new Actions(driver);

[Link](button).build().perform();
[Link](3000);

[Link]([Link]("(//
span[contains(text(),'Copy')])[2]")).click();

[Link]([Link]().alert().getText());

[Link]().alert().accept();
[Link](3000);

[Link](button).build().perform();

[Link](3000);
[Link]([Link]("(//
span[contains(text(),'Paste')])[2]")).click();
[Link]([Link]().alert().getText());
[Link]().alert().accept();

}
Ranjeet kendre

Example 3

package ActionsClass;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class KeyboardActions2 {

public static void main(String[] args) throws


InterruptedException {
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

// Step 2

WebDriver driver = new ChromeDriver();

[Link]().timeouts().implicitlyWait(120,
[Link]);

// ChromeDriver driver1 =new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
key_presses?");

Actions act = new Actions(driver);

[Link](Keys.BACK_SPACE).perform();

[Link]([Link]([Link]("result")).getTex
t());

[Link]([Link]).build().perform();

[Link]([Link]([Link]("result")).getTex
t());

[Link]([Link]).build().perform();
Ranjeet kendre

[Link]([Link]([Link]("result")).getTex
t());

}
}

Example 4
package ActionsClass;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class DoubleClick {


Ranjeet kendre
public static void main(String[] args) throws
InterruptedException {
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

// Step 2

WebDriver driver = new ChromeDriver();

// ChromeDriver driver1 =new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
simple_context_menu.html");

WebElement Double = [Link]([Link]("//


button[@ondblclick=\"myFunction()\"]"));

Actions act = new Actions(driver);

[Link](Double).build().perform();

[Link](2000);

[Link]().alert().accept();

[Link]();
}}
Ranjeet kendre

Example 5

package ActionsClass;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class DragandDrop {

public static void main(String[] args) {

[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

// Step 2

WebDriver driver = new ChromeDriver();

// ChromeDriver driver1 =new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
drag-drop-custom/[Link]");

WebElement Source=[Link]([Link]("box3"));

WebElement dest=[Link]([Link]("box103"));

Actions act =new Actions(driver);

[Link](Source, dest).build().perform();

}
}
Ranjeet kendre

Example 6
package ActionsClass;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class KeyboardActions {

@SuppressWarnings("deprecation")
public static void main(String[] args) throws
InterruptedException {
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

// Step 2

WebDriver driver = new ChromeDriver();

[Link]().timeouts().implicitlyWait(120,
[Link]);
Ranjeet kendre

// ChromeDriver driver1 =new ChromeDriver();

[Link]().window().maximize();

// [Link]("[Link]
[Link]("[Link]
WebElement input1 = [Link]([Link]("email"));
WebElement input2 = [Link]([Link]("pass"));

[Link](2000);

[Link]("Thisismyfirstjavaprogram");

Actions act = new Actions(driver);

// CTRL+A
// [Link]([Link]); //Windowusers
[Link]([Link]); // MacoS
[Link]("a");
[Link]([Link]);
[Link]().perform();

// CTRL+C
// Command+C
[Link]([Link]); // MacoS
[Link]("c");
[Link]([Link]);
[Link]().perform();

// Tab

[Link]([Link]);
[Link]().perform();

// CTRL+V //Command+V
[Link]([Link]); // MacoS
[Link]("v");
[Link]([Link]);
[Link]().perform();

// Compare text
if
([Link]("value").equals([Link]("value"))
) {
[Link]("Correct copied");
} else {
[Link]("Incorrect copied");
}

}}
Ranjeet kendre

Example 6

package ActionsClass;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class KeyboardActions2 {


Ranjeet kendre
public static void main(String[] args) throws
InterruptedException {
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

// Step 2

WebDriver driver = new ChromeDriver();

[Link]().timeouts().implicitlyWait(120,
[Link]);
// ChromeDriver driver1 =new ChromeDriver();
[Link]().window().maximize();
[Link]("[Link]
key_presses?");
Actions act = new Actions(driver);
[Link](Keys.BACK_SPACE).perform();

[Link]([Link]([Link]("result")).getTex
t());
[Link]([Link]).build().perform();
[Link]([Link]([Link]("result")).getTex
t());
[Link]([Link]).build().perform();

[Link]([Link]([Link]("result")).getTex
t());

}
}
Ranjeet kendre

What is JavaScriptExecutor?
JavaScriptExecutor is an Interface that helps to execute JavaScript through Selenium
Webdriver. JavaScriptExecutor provides two methods “executescript” &
“executeAsyncScript” to run JavaScript on the selected window or current page.

Why do we need JavaScriptExecutor?


In Selenium Webdriver, locators like XPath, CSS, etc. are used to identify and perform
operations on a web [Link] case, these locators do not work you can use
JavaScriptExecutor. You can use
JavaScriptExecutor to perform an desired operation on a web element.

Selenium supports javaScriptExecutor. There is no need for an extra plugin or add-on.


You just need to import ([Link]) in the script as to use
[Link]

Example 1

package JavaScriptExecutor;

import [Link];
import [Link];
import [Link];

public class ScrollDownandUP1 {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
JavascriptExecutor Js = (JavascriptExecutor) driver;

//ScrollDown
[Link]("[Link](0,9000)", "");

[Link](4000);
Ranjeet kendre
//ScrollUp
[Link]("[Link](0,-2000)", "");
}

Example 2

package JavaScriptExecutor;

import [Link];
import [Link];
import [Link];

public class ScrollDownandUPTillbottom {

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


{

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

JavascriptExecutor Js = (JavascriptExecutor) driver;


Ranjeet kendre
//ScrollDown

[Link]("[Link](0,[Link])", "");

[Link](4000);

//ScrollUp
[Link]("[Link]=0", "");
}
}

Example 3

package JavaScriptExecutor;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ScrollbyElements {

public static void main(String[] args) throws


InterruptedException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
Ranjeet kendre

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

JavascriptExecutor Js = (JavascriptExecutor) driver;

WebElement Name = [Link]([Link]("//


h1[contains(text(),'W3Schools Spaces')]"));

// Scrollby element
[Link]("arguments[0].scrollIntoView();",
Name);

Example 4

package JavaScriptExecutor;

import [Link];
import [Link];
import [Link];
Ranjeet kendre
public class HorizontalorRightlefscroll {

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


{

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
scrolling");
JavascriptExecutor Js = (JavascriptExecutor) driver;

//ScrollDown
[Link]("[Link](10000,0)", "");

[Link](4000);

//ScrollUp
[Link]("[Link](-2000,0)", "");
}

Example 5
package JavaScriptExecutor;

import [Link];
import [Link];
Ranjeet kendre
import [Link];
import [Link];
import [Link];

public class HighlightBorder {

public static void main(String[] args) {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

WebElement Elemet = [Link]([Link]("//


img[@class=\"fb_logo _8ilh img\"]"));
JavascriptExecutor Js = (JavascriptExecutor) driver;
WebElement Elemet1 = [Link]([Link]("email"));

[Link]("arguments[0].[Link]='15px solid
red'", Elemet);
[Link]("arguments[0].[Link]='5px solid
yellow'", Elemet1);

// ScrollDown
}

Example 6

package JavaScriptExecutor;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class HighlightBorderbyMethod {

public static void main(String[] args) {


Ranjeet kendre

[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

WebElement Elemet = [Link]([Link]("//


img[@class=\"fb_logo _8ilh img\"]"));
WebElement Elemet1 =
[Link]([Link]("email"));
WebElement Elemet2=
[Link]([Link]("pass"));

[Link](driver, Elemet);
[Link](driver, Elemet1);
[Link](driver, Elemet2);

}
public static void drawborder(WebDriver driver,
WebElement element) {

JavascriptExecutor Js = (JavascriptExecutor) driver;


[Link]("arguments[0].[Link]='5px
solid red'",element );

[Link]("arguments[0].[Link]='black'",elem
ent );

}
Ranjeet kendre

Example 7
package JavaScriptExecutor;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class Javascriptsendkeys {

public static void main(String[] args) {

[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
Ranjeet kendre
WebElement Username =
[Link]([Link]("email"));
WebElement Password =
[Link]([Link]("pass"));

JavascriptExecutor js = (JavascriptExecutor) driver;

//Sendkeys
//
[Link]("[Link]('email').value='Tes
t12';");
//
[Link]("[Link]('pass').value='2345
67';");
//
//SecondWay
[Link]("arguments[0].value='"+ "Test"
+"';", Username);
[Link]("arguments[0].value='"+ "Test123"
+"';", Password);

}
Ranjeet kendre

Example 8
package JavaScriptExecutor;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ClickAction {

public static void main(String[] args) {


[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

WebElement Username =
[Link]([Link]("email"));
WebElement Password = [Link]([Link]("pass"));

JavascriptExecutor js = (JavascriptExecutor) driver;

//SecondWay
[Link]("arguments[0].value='"+ "Test" +"';",
Username);
[Link]("arguments[0].value='"+ "Test123"
+"';", Password);

WebElement Loginbutton=[Link]([Link]("//
button[@name=\"login\"]"));

[Link]("arguments[0].click()", Loginbutton);

}
Ranjeet kendre

Example 9

package JavaScriptExecutor;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class Alerts {

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

[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");

// Step 2

WebDriver driver = new ChromeDriver();

// ChromeDriver driver1 =new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

WebElement Account = [Link]([Link]("//


span[contains(text(),'Account & Lists')]"));

Actions act = new Actions(driver);

[Link](Account).build().perform();

[Link]([Link]("(//span[contains(text(),'Sign in') and


@class=\"nav-action-inner\"])[1]")).click();

[Link]([Link]("ap_email")).sendKeys("velocity@[Link]");

[Link]([Link]("continue")).click();

[Link]([Link]("ap_password")).sendKeys("qwertyu");

[Link]([Link]("signInSubmit")).click();

[Link](3000);

boolean Text = [Link]([Link]("//span[@class=\"a-list-


item\"]")).isDisplayed();

[Link](Text);

[Link](driver, "There is an issue with passowrd");


}

public static void GenerateAlerts(WebDriver driver, String Message) {

JavascriptExecutor js =(JavascriptExecutor) driver;


Ranjeet kendre
[Link]("[Link](0,5000)", "");

[Link]("alert('"+Message+"')");
}

What are Web Tables?

Web Tables are like normal tables where the data is presented in a structured form using
rows and columns. The only difference is that they are displayed on the web with the help
of HTML code.
<table> is the HTML tag that is used to de ne a web table. While <th> is used for de ning
the header of the table, <tr> and <td> tags are used for de ning rows and columns
respectively for the web table.

package WebTables;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class Firstprogram1 {

public static void main(String[] args) {

[Link]("[Link]", "/Users/ranjeetkendre/Documents/
chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

JavascriptExecutor js = (JavascriptExecutor) driver;

WebElement Elemet = [Link]([Link]("//h3[contains(text(),'Example')]"));

[Link]("arguments[0].scrollIntoView();", Elemet);

// First way
// Question1 - How many rows in table
int Row = [Link]([Link]("//table[@id=\"customers\"]/tbody/
tr")).size();
[Link]("Total number of rows -->" + Row);

List<WebElement> Row1 = [Link]([Link]("//table[@id=\"customers\"]/


tbody/tr/th"));

[Link]("Total number of rows -->" + [Link]());

// Question - How many columns in table


//
// int col = [Link]([Link]("//table[@id=\"customers\"]/tbody/tr/
th")).size();
// [Link]("Total number of col-->" + col);
//
// // Question3 Retrieve the specific row/col data
//
// String Data = [Link]([Link]("//table[@id=\"customers\"]/tbody/tr[4]/
td[3]")).getText();
//
fi
fi
fi
Ranjeet kendre
// [Link](Data);
//
// // Question 4 Retrieve all row/col data
//
// for (int i = 2; i <= Row; i++) {
//
// for (int j = 1; j <= col; j++) {
//
// String Data1=[Link]([Link]("//table[@id=\"customers\"]/
tbody/tr[i]/td[j]")).getText();
// [Link](Data1 +" || ");
// }
//[Link]();
//}
// }
}
}

Example 2

package WebTables;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
Ranjeet kendre
import [Link];

public class SecondProgram {

public static void main(String[] args) {

[Link]("[Link]", "/Users/ranjeetkendre/
Downloads/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
JavascriptExecutor Js = (JavascriptExecutor) driver;
WebElement Example = [Link]([Link]("//
h3[contains(text(),'Example')]"));
// First way
[Link]("arguments[0].scrollIntoView();", Example);
int Row = [Link]([Link]("//table[@id=\"customers\"]/
tbody/tr")).size();

[Link]("Total no of rows :" + Row);

int Col = [Link]([Link]("//table[@id=\"customers\"]/


tbody/tr/th")).size();
[Link]("Total no of column :" + Col);

// Second way

List<WebElement> Row1 = [Link]([Link]("//


table[@id=\"customers\"]/tbody/tr"));
[Link]("Total no of rows :" + [Link]());

List<WebElement> Col1 = [Link]([Link]("//


table[@id=\"customers\"]/tbody/tr/th"));
[Link]("Total no of column :" + [Link]());

// Retrieve all the data from table

// 2<=7 - True
for (int i = 2; i <= Row; i++) {//Outer loop

// 1<=3 - True
for (int j = 1; j <= Col; j++) {// inner loop

String data = [Link]([Link]("//


table[@id=\"customers\"]/tbody/tr["+2+"]/td["+1+"]"))
.getText();
if ([Link]("Canada")) {

[Link]("Row Number :" + i + ":" + "Col


Number :" + j);

break;

}
}
}
}
}
Ranjeet kendre
How to nd broken links in Selenium

To start with, a link is an HTML object that enables users to migrate from one web page to
another when they click on it. It is a means to navigate between different web pages on the
internet.
A broken link, also often called a dead link, is one that does not work i.e. does not redirect
to the webpage it is meant to. This usually occurs because the website or particular web
page is down or does not exist. When someone clicks on a broken link, an error message
is displayed.
Broken links may exist due to some kind of server error, which, in turn, causes the
corresponding page to malfunction and not be displayed. A valid URL will have a 2xx
HTTP status code. Broken links, which are essentially invalid HTTP requests have 4xx
and 5xx status codes.
The 4xx status code refers to a client-side error, while the 5xx status code usually points to
a server response error.

Example 1

package MultipleLinks;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class HandleLinks {

public static void main(String[] args) {

[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

List<WebElement> Links=[Link]([Link]("a"));

[Link]("Number of link -->"+[Link]());

for(WebElement link :Links) {

[Link]([Link]());
[Link]([Link]("href"));
}}}

[Link]();
fi
Ranjeet kendre
Example 2
package MultipleLinks;

import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class BrokenLinks {

public static void main(String[] args) throws


IOException {

[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

List<WebElement>
Links=[Link]([Link]("a"));
[Link]([Link]());

int Brokenlinks = 0;

for(WebElement element :Links) {

String url =[Link]("href");

if(url==null || [Link]()) {
[Link]("URL is empty or null");
}

URL Link =new URL(url);

HttpsURLConnection httpscode
=(HttpsURLConnection) [Link]();
[Link]();
Ranjeet kendre
//200 - ok
//201 - created
//400 - badreq

if([Link]()>=400) {

[Link]([Link]()+"-->"+url+"is
-->Broken Link");
Brokenlinks++;
}
else {

[Link]([Link]()+"-->"+url+"is
-->valid Link");
}

[Link]("Number of broken links --


>"+Brokenlinks);
[Link]();
}}
Ranjeet kendre

Difference b/w findElement and findElements

findElement: A command to uniquely identify a web element


within the web page.

findElements: A command to identify a list of web elements


within the web page.

Example 1:

package Findelement;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class Findelements {

public static void main(String[] args) {

[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

//1
List<WebElement> Searchbox = [Link]([Link]("//
input[@id=\"twotabsearchtextbox\"]"));

[Link]([Link]("//
input[@id=\"twotabsearchtextbox\"]"));

//2
List<WebElement> Links = [Link]([Link]("//
a[@class=\"nav-a \"]"));

[Link]([Link]());

for (WebElement ele : Links) {


[Link]([Link]());
}

//3.
List<WebElement> Link1 = [Link]([Link]("//
a[@class=\"nav\"]"));

[Link]([Link]());

[Link]();
}

}
Ranjeet kendre

Example 2
package Findelement;

import [Link];
import [Link];
import [Link];
import [Link];

public class Findelement1 {

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


{

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
// Window //[Link]("[Link]",
// "C:\\Installer\\[Link]");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
Ranjeet kendre
//1
WebElement Searchbox=[Link]([Link]("//
input[@id=\"twotabsearchtextbox\"]"));

[Link]("Oneplus");

[Link](3000);

//2
WebElement Links=[Link]([Link]("//
a[@class=\"nav-a \"]"));
[Link]([Link]());

//3
WebElement Links1=[Link]([Link]("//
a[@class=\"navv-a \"]"));
[Link]([Link]());
[Link]();

}
Ranjeet kendre
Ranjeet kendre
What is the difference between the getwindowhandle() and getwindowhandles()?

getwindowhandles() : This is used to get the address of all the open browsers and
returns the data type of Set<String>.

getwindowhandle() : This is used to get the address of the current browser window where
it’s focused on and returns the data type of String.

Example 1:
package WindowHandle;

import [Link];
import [Link];

public class WindowHandle1 {

public static void main(String[] args) {

//Step 11
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
[Link]/auth/login");

String WindowID=[Link]();
//By using getwindowhandle method we can get the ID
of the browserwindow
//27BA56A1569DAAC430BAC41CBF13F90D
//E473800DE99D96E864B254548C57FE28

[Link](WindowID);

Example 2

package WindowHandle;

import [Link];
import [Link];
import [Link];
Ranjeet kendre
import [Link];

import [Link];
import [Link];
import [Link];

public class WindowHandle2 {

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


{

//Step 1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]
login");

[Link](3000);
[Link]([Link]("//a[contains(text(),'OrangeHRM,
Inc')]")).click();

[Link](2000);

Set<String>WindowID=[Link]();

//It is used to store all opened windows ID in the set data.

//First Method
Iterator <String>It = [Link]();

String ParentWindow=[Link]();
String ChildWindow=[Link]();

[Link]("ParentWindow -->"+ParentWindow);
[Link]("ChildWindow -->"+ChildWindow);

//Second Way

ArrayList<String> WindowList = new ArrayList(WindowID);

String Parent=[Link](0);
String Child = [Link](1);

[Link]("ParentWindow-->"+Parent);
[Link]("ChildWindow-->"+Child);
// ArrayList<String>AL=[Link]();

//How to switch selenium focus on child window


[Link]().window(ParentWindow);
[Link]("Parentwindow-->"+[Link]());
Ranjeet kendre

[Link]().window(ChildWindow);
[Link]("ChildWindow-->"+[Link]());

[Link]();

Example 3

package WindowHandle;

import [Link];
import [Link];

import [Link];
Ranjeet kendre
import [Link];
import [Link];

public class WindowHandle3 {

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

//Step 1
[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]("[Link]

[Link](3000);
[Link]([Link]("//a[contains(text(),'OrangeHRM,
Inc')]")).click();

[Link](2000);

Set<String>WindowID=[Link]();
Iterator<String> it = [Link]();

String ParentWindow=[Link]();
String ChildWindow =[Link]();
[Link]("ParentWindow-->"+ParentWindow);
[Link]("Child Window-->"+ChildWindow);

[Link]().window(ParentWindow);
[Link]("ParentWindow"+[Link]());
[Link]().window(ChildWindow);
[Link]("ChildWindow"+[Link]());

[Link]([Link]("Form_submitForm_EmailHomePage")).sendKeys("Test@gmail.
com");
[Link]([Link]("Form_submitForm_action_request")).click();

[Link]().window(ParentWindow);

[Link]([Link]("//input[@class=\"oxd-input oxd-input--
active\"]")).sendKeys("Test123");
[Link]([Link]("//
input[@type=\"password\"]")).sendKeys("Tes123");
[Link]([Link]("//button[@type=\"submit\"]")).click();

[Link]();

}
Ranjeet kendre

What is Page Object Model in Selenium?

Page Object Model, also known as POM, is a design pattern in Selenium that creates an
object repository for storing all web elements. It helps reduce code duplication and
improves test case maintenance.
In Page Object Model, consider each web page of an application as a class le. Each
class le will contain only corresponding web page elements. Using these elements,
testers can perform operations on the website under test.

Advantages of Page Object Model


• Easy Maintenance: POM is useful when there is a change in a UI element or a
change in action. An example would be: a drop-down menu is changed to a radio
button. In this case, POM helps to identify the page or screen to be modi ed. As
every screen will have different Java les, this identi cation is necessary to make
changes in the right les. This makes test cases easy to maintain and reduces
errors.
fi
fi
fi
fi
fi
fi
Ranjeet kendre
• Code Reusability: As already discussed, all screens are independent. By using
POM, one can use the test code for one screen, and reuse it in another test case.
There is no need to rewrite code, thus saving time and effort.
• Readability and Reliability of Scripts: When all screens have independent java
les, one can quickly identify actions performed on a particular screen by navigating
through the java le. If a change must be made to a speci c code section, it can be
ef ciently done without affecting other les.
What is Page Factory in Selenium?
Page Factory is a class provided by Selenium WebDriver to support Page Object Design
patterns. In Page Factory, testers use @FindBy annotation. The initElements method is
used to initialize web elements.
• @FindBy: An annotation used in Page Factory to locate and declare web elements
using different locators. Below is an example of declaring an element
using @FindBy@FindBy(id="elementId") WebElement element;

Similarly, one can use @FindBy with different location strategies to nd web
elements and perform actions on them. Below are locators that can be used:
• ClassName
• CSS
• Name
• Xpath
• TagName
• LinkText
• PartialLinkText

• initElements(): initElements is a static method in Page Factory class. Using
the initElements method, one can initialize all the web elements located
by @FindBy annotation.

Example :
package PageObject_WithDDF;
import [Link];
import [Link];
import [Link];
import [Link];

public class LoginPage {

WebDriver driver;

public LoginPage(WebDriver driver) {

//initialization
[Link] = driver;
[Link](driver, this);
fi
fi
fi
fi
fi
fi
Ranjeet kendre
}

// pagefactory
@FindBy(xpath = "//input[@name=\"username\"]")
public WebElement useremail;

// WebElement element=[Link]([Link]("username"));

@FindBy(xpath = "//input[@name=\"password\"]")
private WebElement Password;

@FindBy(xpath = "//button[@type=\"submit\"]")
public WebElement Button;

public void Usermail(String email) {


[Link](email);
}

public void Password1(String pass) {


[Link](pass);
}

public void Login() {


[Link]();

public void GoTO() {

[Link]("[Link]
auth/login");
}

package PageObject_WithDDF;

import [Link];
import [Link];
import [Link];
import [Link];

public class DasboardPage {

WebDriver driver;
//1.

@FindBy(xpath = "//p[@class=\"oxd-userdropdown-name\"]")
WebElement Name;

@FindBy(xpath = "//p[@class=\"oxd-text oxd-text--p\"]")


WebElement Time;

//2.

public DasboardPage(WebDriver driver) {

[Link]=driver;
Ranjeet kendre
[Link](driver, this);
}

//3.

public void Namevalidation() {


String Text=[Link]();
if([Link]("Ajay Singh")) {
[Link]("Correct username");
}
else {
[Link]("Incorrect username");
}
}

public void TimeAt() {

boolean Time1=[Link]();
[Link](Time1);
}
}

package PageObject_WithDDF;

import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class BaseorTestclass {

public static void main(String[] args) throws


EncryptedDocumentException, IOException {

[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");

WebDriver driver = new ChromeDriver();

[Link]().window().maximize();

[Link]().timeouts().implicitlyWait([Link](20));

LoginPage LP = new LoginPage(driver);


//To fetch data from excelsheet

String path ="/Users/ranjeetkendre/eclipse-workspace/


11March_Automation/Readdata/11March_DDF.xlsx";

FileInputStream file =new FileInputStream(path);


Ranjeet kendre

Sheet Data=[Link](file).getSheet("Sheet1");

[Link]();
String UserID=[Link](1).getCell(0).getStringCellValue();
[Link](UserID);

String
Password=[Link](1).getCell(1).getStringCellValue();

LP.Password1(Password);
[Link]();

DasboardPage DP =new DasboardPage(driver);


[Link]();
[Link]();
[Link]();
}

}
Ranjeet kendre

Interview Question

1. What is Automation Testing?


Automation testing is the process of testing the software using an automation tool
to nd the defects. In this process, executing the test scripts and generating the
results are performed automatically by automation tools. Some most popular tools
to do automation testing are HP QTP/UFT, Selenium WebDriver, etc.,

2. What are the bene ts of Automation Testing?


· Saves time and money. Automation testing is faster in execution.
· Reusability of code. Create one time and execute multiple times with less or no
maintenance.

· Easy reporting. It generates automatic reports after test execution.


· Easy for compatibility testing. It enables parallel execution in the combination
of different OS and browser environments.
· Low-cost maintenance. It is cheaper compared to manual testing in a long run.
· Automated testing is more reliable.
· Automated testing is more powerful and versatile.
· It is mostly used for regression testing. Supports execution of repeated test
cases.
· Minimal manual intervention. Test scripts can be run unattended.
· Maximum coverage. It helps to increase the test coverage.

3. What type of tests have you automated?


Our main focus is to automate test cases to do Regression testing, Smoke testing,
and Sanity testing. Sometimes based on the project and the test time estimation,
we do focus on End to End testing.

4. How many test cases you have automated per day?


It depends on Test case scenario complexity and length. I did automate 2-5 test
scenarios per day when the complexity is limited. Sometimes just 1 or fewer test
scenarios in a day when the complexity is high.

5. What is a Framework?
A framework de nes a set of rules or best practices which we can follow in a
systematic way to achieve the desired results. There are different types of
automation frameworks and the most common ones are:
• Data Driven Testing Framework
• Keyword Driven Testing Framework
fi
fi
fi
Ranjeet kendre
• Hybrid Testing Framework

6. Have you created any Framework?


If you are a beginner: No, I didn’t get a chance to create a framework. I have used
the framework which is already available.
If you are an experienced tester: Yes, I have created a framework. Or I have
involved in the creation of the framework.

7. Can you explain the Framework which you have used in your Selenium Project?

8. Why do you prefer Selenium Automation Tool?

· Free and open source


· Have large user base and helping communities
· Cross browser compatibility
· Platform compatibility
· Multiple programming languages support

9. What is Selenium?
Selenium is an open source (free) automated testing suite to test web applications.
It supports different platforms and browsers. It has gained a lot of popularity in
terms of web-based automated testing and giving a great competition to the famous
commercial tool HP QTP (Quick Test Professional) AKA HP UFT (Uni ed Functional
Testing).
Selenium is a set of different software tools. Each tool has a different approach in
supporting web based automation testing.
It has four components namely,
i Selenium IDE (Integrated Development Environment)
ii Selenium RC (Remote Control) – selenium 1
iii Selenium WebDriver – selenium 2 & 3
iv Selenium Grid

10. What is Selenium IDE?


Selenium IDE (Integrated Development Environment) is a Firefox plugin. It is the
simplest framework in the Selenium Suite. It allows us to record and playback the
scripts. Even though we can create scripts using Selenium IDE, we need to use
Selenium RC or Selenium WebDriver to write more advanced and robust test
cases.
fi
Ranjeet kendre

11. What is Selenese?


Selenese is the language which is used to write test scripts in Selenium IDE.

13. What is Selenium RC?


Selenium RC AKA Selenium 1. Selenium RC was the main Selenium project for a
long time before the WebDriver merge brought up Selenium 2. Selenium 1 is still
actively supported (in maintenance mode). It relies on JavaScript for automation.
It supports Java, Javascript, Ruby, PHP, Python, Perl and C#. It supports almost
every browser out there.

14. What is Selenium WebDriver?


Selenium WebDriver AKA Selenium 2 is a browser automation framework that
accepts commands and sends them to a browser. It is implemented through a
browser-speci c driver. It controls the browser by directly communicating with it.
Selenium WebDriver supports Java, C#, PHP, Python, Perl, Ruby.

15. What is Selenium Grid?


Selenium Grid is a tool used together with Selenium RC to run tests on different
machines against different browsers in parallel. That is, running multiple tests at the
same time against different machines running different browsers and operating
systems.

In simple words, it is used to distribute your test execution on multiple platforms and
environments concurrently.

17. What are the advantages of Selenium Grid?


It allows running test cases in parallel thereby saving test execution time.
It allows multi-browser testing
It allows us to execute test cases on multi-platform

20. What are the types of WebDriver APIs available in Selenium?


• Firefox Driver
• Gecko Driver
• InternetExplorer Driver
• Chrome Driver
• HTMLUNIT Driver
• Opera Driver
fi
Ranjeet kendre
• Safari Driver
• Android Driver
• iPhone Driver

21. Which WebDriver implementation claims to be the fastest?

The fastest implementation of WebDriver is the HTMLUnitDriver. It is because the


HTMLUnitDriver does not execute tests in the browser.

22. What are the Programming Languages supported by Selenium WebDiver?


• Java
• C#
• Python
• Ruby
• Perl
• PHP

23. What are the Operating Systems supported by Selenium WebDriver?


• Windows
• Linux
• Apple

24. What are the Open-source Frameworks supported by Selenium WebDriver?


• JUnit
• TestNG
• CUCUMBER
• JBHEAVE

25. What are the Locators available in Selenium?


Different types of locators are:
1 ID –
2 ClassName –
3 Name –
4 TagName –
5 LinkText –
6 PartialLinkText –
7 XPath –
8 CSS Selector –

26. What is a XPath?


Ranjeet kendre
XPath is used to locate the elements. Using XPath, we could navigate through
elements and attributes in an XML document to locate web elements such as
textbox, button, checkbox, Image etc., in a web page.

27. What is the difference between “/” and “//”


Single Slash “/” – Single slash is used to create XPath with absolute path i.e. the
XPath would be created to start selection from the document node/start node

Double Slash “//” – Double slash is used to create XPath with relative path i.e. the
XPath would be created to start selection from anywhere within the document.

28. What is the difference between Absolute Path and Relative Path?
Absolute XPath starts from the root node and ends with desired descendant
element’s node. It starts with top HTML node and ends with input node. It starts
with a single forward slash(/) as shown below.
/html/body/div[3]/div[1]/form/table/tbody/tr[1]/td/input
Relative XPath starts from any node in between the HTML page to the current
element’s node(last node of the element). It starts with a single forward slash(//) as
shown below.
//input[@id=’email’]

29. What is the difference between Assert and Verify in Selenium?


1 WebDriver driver = new FirefoxDriver();
2
3 instead of creating
4
5 FirefoxDriver driver = new FirefoxDriver();
1 driver. ndElement([Link](“Software Testing Material Website”)).click();
1
1 [Link](“[Link]
3 1 4 boolean elePresent = driver. ndElement([Link](“xpath”))
.isDisplayed();
3 1 4 boolean eleSelected= driver. ndElement([Link](“xpath”)
).isSelected();
3 1 4 boolean eleEnabled= driver. ndElement([Link](“xpath”)
).isEnabled();
Assert: In simple words, if the assert condition is true then the program control will
execute the next test step but if the condition is false, the execution will stop and
further test step will not be executed.

Verify: In simple words, there won’t be any halt in the test execution even though
the verify condition is true or false.
For detailed post check the below link.
fi
fi
fi
fi
Ranjeet kendre

30. What are Soft Assert and Hard Assert in Selenium?


Soft Assert: Soft Assert collects errors during @Test Soft Assert does not throw an
exception when an assert fails and would continue with the next step after the
assert statement

Hard Assert: Hard Assert throws an AssertException immediately when an assert


statement fails and test suite continues with next @Test

31. What are the veri cation points available in Selenium?


In Selenium IDE, we use Selenese Verify and Assert Commands as Veri cation
points

In Selenium WebDriver, there is no built-in features for veri cation points. It totally
depends on our coding style. some of the Veri cation points are
To check for page title
To check for certain text
To check for certain element (text box, button, drop down, etc.)

32. How to launch a browser using Selenium WebDriver?


WebDriver is an Interface. We create Object of a WebDriver Interface.

<2.53 – no geckodriver
3.x – geckodriver for FF

To launch Firefox Driver:


WebDriver driver = new FirefoxDriver();
To launch Chrome Driver:
WebDriver driver = new ChromeDriver();
To launch Internet Explorer Driver:
WebDriver driver = new InternetExplorerDriver();

33. Is the FirefoxDriver a Class or an Interface?


FirefoxDriver is a Java class, and it implements the WebDriver interface.
fi
fi
fi
fi
Ranjeet kendre

34. What is the super interface of WebDriver?


SearchContext.

35. Explain the line of code Webdriver driver = new FirefoxDriver(); ?

‘WebDriver‘ is an interface and we are creating an object reference of type


WebDriver instantiating an object of FirefoxDriver class.

36. We do create a reference variable ‘driver’ of type WebDriver


WebDriver driver = new FirefoxDriver();

instead of creating

FirefoxDriver driver = new FirefoxDriver();


What is the purpose of doing this way?
f we create a reference variable driver of type WebDriver then we could use the
same driver variable to work with any browser of our choice such as IEDriver,
SafariDriver etc.,

//FirefoxDriver driver = new FirefoxDriver();


ChromeDriver driver = new ChromeDriver();
[Link](“[Link]

WebDriver driver = new FirefoxDriver();

37. What are the different exceptions you have faced in Selenium WebDriver?
• WebDriverException
• TimeoutException
• NoAlertPresentException
• NoSuchWindowException
• NoSuchElementException
• StaleElementReferenceException
• IllegalStateException

38. How To Login Into Any Site If It Is Showing Any Authentication Pop-Up For
Username And Password?
To do this we pass username and password with the URL
[Link]
e.g. [Link]
Ranjeet kendre

39. What are the types of waits available in Selenium WebDriver?


In Selenium we could see three types of waits such as Implicit Waits, Explicit Waits
and Fluent Waits.
• Implicit Waits –
• Explicit Waits –
• Fluent Waits –
• PageLoadTimeOut
• [Link]() – static wait

40. What is Implicit Wait In Selenium WebDriver?


Implicit waits tell to the WebDriver to wait for a certain amount of time before it
throws an exception. Once we set the time, WebDriver will wait for the element
based on the time we set before it throws an exception. The default setting is 0
(zero). We need to set some wait time to make WebDriver to wait for the required
time.

41. What is WebDriver Wait In Selenium WebDriver?


WebDriverWait is applied on a certain element with de ned expected condition and
time. This wait is only applied to the speci ed element. This wait can also throw an
exception when an element is not found.

42. What is Fluent Wait In Selenium WebDriver?


FluentWait can de ne the maximum amount of time to wait for a speci c
condition and frequency with which to check the condition before throwing an
“ElementNotVisibleException” exception.

43. How to input text in the text box using Selenium WebDriver?
By using sendKeys() method
WebDriver driver = new FirefoxDriver();
[Link](“[Link]
driver. ndElement([Link](“xpath”)).sendKeys(“test”);

44. How to input text in the text box without calling the sendKeys()?
// To initialize js object
JavascriptExecutor JS = (JavascriptExecutor)driver;
// To enter username
[Link](“[Link](‘User’).value=[Link]'”);
fi
fi
fi
fi
fi
Ranjeet kendre

45. How to clear the text in the text box using Selenium WebDriver?
By using clear() method
WebDriver driver = new FirefoxDriver();
[Link](“[Link]
driver. ndElement([Link](“xpath_of_element1”)).sendKeys(“Software Testing
Material Website”);
driver. ndElement([Link](“xpath_of_element1”)).clear();

46. How to get a text of a web element?


By using getText() method

47. How to get an attribute value using Selenium WebDriver?


By using getAttribute(value);

48. How to click on a hyperlink using Selenium WebDriver?


We use click() method in Selenium to click on the hyperlink
driver. ndElement([Link](“Software Testing Material Website”)).click();

49. How to submit a form using Selenium WebDriver?


We use “submit” method on element to submit a form
driver. ndElement([Link](“form_1”)).submit();
Alternatively, you can use click method on the element which does form submission

50. How to press ENTER key on text box In Selenium WebDriver?


To press ENTER key using Selenium WebDriver, We need to use
Selenium Enum Keys with its constant ENTER.
driver. ndElement([Link](“xpath”)).sendKeys([Link]);

51. How to pause a test execution for 5 seconds at a speci c point?


By using [Link](long milliseconds) method we could pause the
execution for a speci c time. To pause 5 seconds, we need to pass parameter as
5000 (5 seconds)
[Link](5000)

52. Is Selenium Server needed to run Selenium WebDriver Scripts?


fi
fi
fi
fi
fi
fi
fi
Ranjeet kendre
When we are distributing our Selenium WebDriver scripts to execute using
Selenium Grid, we need to use Selenium Server.

53. What happens if I run this command.


[Link](“[Link]”) ;
An exception is thrown. We need to pass HTTP protocol within [Link]() method.
[Link](“[Link]

54. What is the alternative to [Link]() method to open an URL using Selenium
WebDriver?
Alternative method to [Link](“url”) method is [Link](“url”)

55. What is the difference between [Link]() and [Link](“url”)?


[Link](): To open an URL and it will wait till the whole page gets loaded
[Link](): To navigate to an URL and It will not wait till the whole page
gets loaded

56. Can I navigate back and forth in a browser in Selenium WebDriver?


We use Navigate interface to do navigate back and forth in a browser. It has
methods to move back, forward as well as to refresh a page.

[Link]().forward(); – to navigate to the next web page with reference to the


browser’s history

[Link]().back(); – takes back to the previous webpage with reference to the


browser’s history

[Link]().refresh(); – to refresh the current web page thereby reloading all


the web elements

[Link]().to(“url”); – to launch a new web browser window and navigate to


the speci ed URL

57. What are the different types of navigation commands?


Refer above question (Can I navigate back and forth in a browser)

58. How to fetch the current page URL in Selenium?


To fetch the current page URL, we use getCurrentURL()
[Link]();
fi
Ranjeet kendre

59. How can we maximize browser window in Selenium?


To maximize browser window in selenium we use maximize() method. This method
maximizes the current window if it is not already maximized
[Link]().window().maximize();
60. How to delete cookies in Selenium?
To delete cookies we use deleteAllCookies() method
[Link]().deleteAllCookies();

61. What are the ways to refresh a browser using Selenium WebDriver?
There are multiple ways to refresh a page in selenium
• Using [Link]().refresh() command as mentioned in the question 45
• Using [Link](“URL”) on the current URL or using [Link]()
• Using [Link]().to(“URL”) on the current URL or
[Link]().to([Link]());
• Using sendKeys(Keys.F5) on any textbox on the webpage

62. What is the difference between [Link]() and


[Link]() in Selenium WebDriver?

[Link]() – It returns a handle of the current page (a unique


identi er)
[Link]() – It returns a set of handles of the all the pages
available.

63. What is the difference between [Link]() and [Link]() methods?


Purpose of these two methods ([Link] and [Link]) is almost same. Both
allow us to close a browser but still, there is a difference.
[Link](): To close current WebDriver instance
[Link](): To close all the opened WebDriver instances

64. What is the difference between driver. ndElement() and driver. ndElements()
commands?
The difference between driver. ndElement() and driver. ndElements() commands
is-
fi
fi
fi
fi
fi
Ranjeet kendre
• ndElement() returns a single WebElement (found rst) based on the locator
passed as parameter. Whereas ndElements() returns a list of WebElements, all
satisfying the locator value passed.
• Syntax of ndElement()-
• WebElement textbox = driver. ndElement([Link](“textBoxLocator”));
• Syntax of ndElements()-
• List <WebElement> elements = element. ndElements([Link](“value”));
• Another difference between the two is- if no element is found then ndElement()
throws NoSuchElementException whereas ndElements() returns a list of 0
elements.

List<WebElement> list = driver. ndElements([Link](“a”));


Sop([Link]()); ==40

65. How to nd whether an element is displayed on the web page?


WebDriver facilitates the user with the following methods to check the visibility of
the web elements. These web elements can be buttons, drop boxes, checkboxes,
radio buttons, labels etc.
1 isDisplayed()
2 boolean elePresent = driver. ndElement([Link](“xpath”)).isDisplayed();
1 isSelected()
2 boolean eleSelected= driver. ndElement([Link](“xpath”)).isSelected();
1 isEnabled()
2 boolean eleEnabled= driver. ndElement([Link](“xpath”)).isEnabled();

66. How to select a value in a dropdown?


By using Select class
WebElement mySelectElement = driver. ndElement([Link](“dropdown”));

Select dropdown = new Select(mySelectElement);

[Link](Text);
[Link](Index);
[Link](Value);

67. How to capture Screenshot in Selenium WebDriver?


By using TakesScreenshot Interface

In Selenium 3, we may face few issues while capturing Screenshots. To overcome


we use aShot utility. Click on below links to see posts related to the normal way of
capturing a screenshot and capturing a screenshot using aShot utility.
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
Ranjeet kendre

68. How to mouse hover on a web element using WebDriver?


By using Actions class
WebElement ele = driver. ndElement([Link](“xpath”));
//Create object ‘action’ of an Actions class
Actions action = new Actions(driver);
//Mouseover on an element
[Link](ele).build().perform();

69. How can we handle web based pop-up?


To handle alerts popups we need to do switch to the alert window and call Selenium
WebDriver Alert API methods.

70. How can we handle windows based pop up?


Selenium doesn’t support windows based applications. It is an automation testing
tool which supports only web application testing. We could handle windows based
popups in Selenium using some third party tools such as AutoIT, SIKULI, Robot
class etc.

71. How to handle hidden elements in Selenium WebDriver?


It is one of the most important selenium interview questions.
We can handle hidden elements by using javaScript executor
(JavascriptExecutor(driver)).executeScript(“[Link](El
ementLocator).click();”);

72. How can you nd Broken Links in a page using Selenium WebDriver?

73. How to nd more than one web element in the list?


// To store the list
List <WebElement> eleList = driver. ndElements([Link](“xpath”));
// To fetch the size of the list
int listSize = [Link]();
//for loop
for (int i=0; i<listSize; i++)
{
// Clicking on each link
fi
fi
fi
fi
Ranjeet kendre
[Link](i).click();
// Navigating back to the previous page that stores the links
[Link]().back();
}

74. How to read a JavaScript variable in Selenium WebDriver?


By using JavascriptExecutor
// To initialize the JS object.
JavascriptExecutor JS = (JavascriptExecutor) webdriver;

// To get the site title.


String title = (String)[Link](“return [Link]”);
[Link](“Title of the webpage : ” + title);

75. How do you read test data from excels?


Test data can ef ciently be read from excel using JXL or POI API. POI API has
many advantages than JXL.

76. Is it possible to automate the captcha using Selenium?


No, It’s not possible to automate captcha and bar code reader.

77. List some scenarios which we cannot automate using Selenium WebDriver?
1. Bitmap comparison Is not possible using Selenium WebDriver
2. Automating Captcha is not possible using Selenium WebDriver
3. We can not read bar code using Selenium WebDriver
4. windows OS based pop ups
5. third party calendars/element
6. Image
7. Word/PDF

78. What is Object Repository in Selenium WebDriver?


Object Repository is used to store element locator values in a centralized location
instead of hard coding them within the scripts. We do create a property le
(.properties) to store all the element locators and these property les act as an
object repository in Selenium WebDriver.
fi
fi
fi
Ranjeet kendre

79. How can you use the Recovery Scenario in Selenium WebDriver?
By using “Try Catch Block” within Selenium WebDriver Java tests.
try {
[Link](“[Link]”);
}catch(Exception e){
[Link]([Link]());
}

80. How to Upload a le in Selenium WebDriver?


There are two cases which are majorly used to upload a le in Selenium WebDriver
such as using SendKeys Method and using AutoIT Script.

Browser Button – type =“ le”


SendKeys (c:\test\[Link]);

81. How to Download a le in Selenium WebDriver?


By using AutoIT script, we could download a le in Selenium WebDriver.

82. How to run Selenium WebDriver Test from the command line?

Class A{

cd c
c: javac [Link]
c: java [Link]

java [Link] C:Users Desktop [Link]

83. How to switch between frames in Selenium?


By using the following code, we could switch between frames.
[Link]().frame();

84. How to connect a Database in selenium?


fi
fi
fi
fi
fi
Ranjeet kendre
As we all know Selenium WebDriver is a tool to automate User Interface. We could
only interact with Browser using Selenium WebDriver.
We use JDBC Driver to connect the Database in Selenium (While using Java
Programming Language).

85. How To Resize Browser Window Using Selenium WebDriver?


To resize the browser window to particular dimensions, we use ‘Dimension’ class to
resize the browser window.

//Create object of Dimensions class


Dimension d = new Dimension(480,620);
//Resize the current window to the given dimension
[Link]().window().setSize(d);

86. How To Scroll Web Page Down Or UP Using Selenium WebDriver?


JavaScript scrollBy() method scrolls the document by the speci ed number of
pixels.

87. How To Perform Right Click Action (Context Click) In Selenium WebDriver?
We use Actions class in Selenium WebDriver to do Right-Click (Context Click)
action.

[Link](driver. ndElement([Link]()).build().perform();

88. How To Perform Double Click Action In Selenium WebDriver?


We use Actions class to do Double click action in selenium.

89. How To Perform Drag And Drop Action in Selenium WebDriver?


We use Actions class to do Drag And Drop Action
fi
fi
Ranjeet kendre
90. How To Highlight Element Using Selenium WebDriver?
By using JavascriptExecutor interface, we could highlight the speci ed element

91. Tell me your Day to Day activities as QA?


First thing I do after login in my system. I check the active sprint in Jira for our project code. There
I can see my assigned open tasks. After that I will check my mail if there is any important mail I
need to take action on. Then we have our daily scrum meeting where we used to tell our previous
day actions what we did, what we are planning for today and if we have any blocker to discuss.
Product owner and scrum master help us to resolve that blocker. After that I need to take the
pending task and do needed action whether creating test case, Execution, Defect retesting if any.

92. Do you have created framework from scratch, or you have maintained that?
I have not created Framework from scratch by myself but yes, I was part of framework creation and
created some part of it.

93. How much you rate yourself in Java out of 10?


Out of 10 I will rate myself 8 in java as QA Automation engineer.

94. Can you tell me Oops concepts and relate it with your Framework?
We have Polymorphism, Inheritance, Encapsulation and Abstraction in Oops. So, we will start with
1) DATA ABSTRACTION : Data Abstraction means to handle complexity by hiding unnecessary
details from the user. In java, abstraction is achieved by interfaces and abstract classes. We can
achieve 100% abstraction using interfaces.
In Selenium, WebDriver itself acts as an interface. Consider the below statement:
WebDriver driver = new ChromeDriver();
We initialize the Chrome Browser using Selenium Webdriver. It means we are creating a reference
variable (driver) of the interface (WebDriver) and creating an Object. Here WebDriver is an
Interface and ChromeDriver is a class.
We can apply Data Abstraction in a Selenium framework by using the Page Object Model design
pattern. We de ne all our locators and their methods in the page class. We can use these locators in
our tests but we cannot see the implementation of their underlying methods. So we only show the
locators in the tests but hide the implementation. This is a simple example of how we can use Data
Abstraction in our Automation Framework.
2) ENCAPSULATION : Encapsulation is de ned as the wrapping up of data under a single unit. It
is the mechanism that binds together code and the data it manipulates. Encapsulation can be
achieved by: Declaring all the variables in the class as private and writing public methods in the
class to set and get the values of variables. All the classes in an Automation Framework are an
example of Encapsulation. In Page Object Model classes, we declare the data members using
@FindBy and initialization of data members will be done using Constructor to utilize those in
methods.

3) INHERITANCE Inheritance is the mechanism in java by which one class is allowed to inherit the
features ( elds and methods) of another class. We can apply Inheritance in our Automation
Framework by creating a Base Class to initialize the WebDriver interface, browsers, waits, reports,
logging, etc. and then we can extend this Base Class and its methods in other classes like Tests or
Utilities. This is a simple example of how we can apply Inheritance in our framework.

4) POLYMORPHISM Polymorphism allows us to perform a single action in different ways. In Java


polymorphism can be achieved by two ways:
Method Overloading: When there are multiple methods with same name but different parameters
fi
fi
fi
fi
Ranjeet kendre
then these methods are said to be overloaded. Methods can be overloaded by change in number of
arguments or/and change in type of arguments. In Selenium Automation, Implicit wait is an
example of Method Overloading. In Implicit wait we use different time stamps such as SECONDS,
MINUTES, HOURS etc. –
Method Overriding: It occurs when a derived class has a de nition for one of the member functions
of the base class. That base function is said to be overridden. In Selenium Automation, Method
Overriding can be achieved by overriding any WebDriver method. For example, we can override
the ndElement method In assertion we have used overload because in assertion we used to like
[Link](actual, expected) and second time we can use same [Link](actual, expected, message).
fi
fi

You might also like