Software Testing: Manual vs Automation
Software Testing: Manual vs Automation
Automation 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.
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.
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
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.
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.
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
WebDriver explanation
package Demo;
import [Link];
import [Link];
import [Link];
//Macos
[Link]("[Link]",
"Usersranjeetkendre/Documents/chromedriver");
//Window
//
[Link]("[Link]","C\Installer\chromedr
[Link]");
Ranjeet kendre
WebDriver driver = new ChromeDriver();
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];
// [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];
// [Link]
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
// [Link] 2
// [Link]
[Link]("[Link]
Ranjeet kendre
[Link](5000);
[Link]();
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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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];
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");
[Link]("[Link]
[Link](URL);
if([Link]("[Link]
[Link]("Correct URL");
else {
[Link]("Incorrect URL");
}
[Link]();
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];
// 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
// [Link]
[Link]("[Link]
}
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];
[Link]("[Link]
web/[Link]/auth/login");
[Link]().window().maximize();
[Link](5000);
[Link]([Link]("//
a[contains(text(),'OrangeHRM, Inc')]")).click();
[Link](5000);
[Link]();
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];
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");
[Link](4000);
[Link]().window().maximize();
[Link]().to("[Link]
[Link](4000);
[Link]().to("[Link]
[Link]/web/[Link]/auth/login");
[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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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]();
}
}
[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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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.
[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 :
Example :
package Locaters;
import [Link];
import [Link];
import [Link];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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
[Link]([Link](“//Input[@Id=\”Dest\"]"));
Example :
package Locaters;
import [Link];
import [Link];
import [Link];
// Syntax - //[Link]([Link]("Xpath
expression")
//Step 1 :
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
//Step 2
//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
package Locaters;
import [Link];
import [Link];
import [Link];
//Step 2
//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();
}
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];
// Syntax - //[Link]([Link]("Xpath
expression")
//Step 1 :
[Link]("[Link]",
"/Users/ranjeetkendre/Documents/chromedriver");
//Step 2
//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
// [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];
// Syntax - //[Link]([Link]("Xpath
expression")
//Step 1 :
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");
//Step 2
//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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
//[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 {
// Step2
[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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
// Step2
[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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
//Step2
[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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
// Step2
[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];
//Step 1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
[Link]("[Link]
[Link]().window().maximize();
[Link]([Link]("Forgotten
passwor?")).click();
//[Link]([Link]("Create a
Page")).click();
[Link](5000);
[Link]();
import [Link];
fi
Ranjeet kendre
import [Link];
import [Link];
//Step 1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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];
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/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 :
//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];
//[Link]
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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]([Link]("input#username")).sendKeys("vel
coity@[Link]");
[Link]([Link]("input#password")).sendKeys("er2
3t");
[Link]([Link]("[name=\"email\"]")).sendKeys("1
2355");
[Link]([Link]("[name=\"pass\"]")).sendKeys("12
34");
[Link]([Link]("input[name=\"pass\"]")).sendKey
s("13445");
[Link]([Link]("input[name=\"pass\"]")).sendKey
s("1234");
[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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
[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];
[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");
[Link]().window().maximize();
[Link]("[Link]
[Link]("234567");
[Link](2000);
[Link]();
[Link](2000);
[Link]("Rahul");
[Link](2000);
[Link]();
}
package WebelementMethods;
import [Link];
import [Link];
import [Link];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
Ranjeet kendre
[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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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];
[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];
// 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();
[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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
[Link]().window().maximize();
Ranjeet kendre
[Link]("[Link]
if([Link](Actualtext)) {
[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();
• 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];
[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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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");
// selectByVisibleText(String text)
//[Link]("4");
// selectByVisibleText(String text)
//[Link]("Mar");
// selectByVisibleText(String text)
//[Link]("2022");
//[Link]
//[Link]
Ranjeet kendre
Select Seclect7 = new Select(Day);
[Link](4);
}
Ranjeet kendre
Example 3
package ListBox;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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");
ListBox(Day,Date[0]);
ListBox(Month,Date[1]);
ListBox(Year,Date[2]);
// ListBox(Day,"22");
// ListBox(Month,"3");
// ListBox(Year, "2019");
Example 4
package ListBox;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
// Step 1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
// Step 2
[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");
// Question1
// How will u get the total no size of list
// Question 2
// How will u print all the values
// 0 ;0<31
// 1<31
for (int i = 0; i < [Link](); i++) {
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];
@SuppressWarnings("deprecation")
public static void main(String[] args) throws
InterruptedException {
//Step -1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
[Link]().window().maximize();
[Link]("[Link]
[Link]().timeouts().implicitlyWait(20,
[Link]);
[Link](4000);
[Link]([Link]("src")).sendKeys("Pune");
// [Link](3000);
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](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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
// Step 2
[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");
List<WebElement> V1 =
[Link]([Link](element));
[Link](V1);
[Link]([Link]());
[Link]([Link](i).getText());
if ([Link](i).getText().equals(values)) {
[Link](i).click();
}}}}
Ranjeet kendre
Parameterization
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];
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");
[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];
String data =
[Link](file).getSheet("Sheet1").getRow(0).getCell(
0).getStringCellValue();
[Link](data);
String data1 =
[Link](file1).getSheet("Sheet1").getRow(1).getCell
(0).getStringCellValue();
[Link](data1);
String data2 =
[Link](file2).getSheet("Sheet1").getRow(1).getCell
(1).getStringCellValue();
[Link](data2);
double data3 =
[Link](file3).getSheet("Sheet2").getRow(0).getCell
(0).getNumericCellValue();
[Link](data3);
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];
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
• 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];
//Step 1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
//Step 2
WebDriver driver =new ChromeDriver();
//Step 3
[Link]().window().maximize();
[Link]("[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];
[Link]("[Link]", "/Users/
ranjeetkendre/Downloads/chromedriver");
[Link]().window().maximize();
[Link]("[Link]
[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];
[Link]("[Link]", "/Users/
ranjeetkendre/Downloads/chromedriver");
[Link]().window().maximize();
[Link]("[Link]
[Link](Source, Dest);
[Link]();
}}
Ranjeet kendre
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.
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];
[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];
[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];
[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");
[Link]("[Link]
[Link]().window().maximize();
[Link]([Link]("//a[contains(text(),'Iframe with in an
Iframe')]")).click();
[Link]().frame(Outerframe);
[Link](text);
Ranjeet kendre
[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];
[Link]("[Link]
filename=tryhtml_iframe_height_width");
[Link]().window().maximize();
[Link]().frame("iframeResult");
[Link](3000);
[Link]().frame(0);
[Link](Text);
[Link]().parentFrame();
[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
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.
Alert interface provides the below few methods which are widely used in Selenium Webdriver.
Example :
package Popups;
import [Link];
import [Link];
Ranjeet kendre
import [Link];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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];
[Link]().window().maximize();
[Link]("[Link]
javascript_alerts");
Ranjeet kendre
[Link]([Link]("//
button[contains(text(),'Click for JS Alert')]")).click();
[Link](3000);
[Link]().alert().accept();
[Link](3000);
[Link](Text);
[Link]();
}
Example 3
package Popups;
import [Link];
import [Link];
import [Link];
import [Link];
[Link]().window().maximize();
[Link]("[Link]
javascript_alerts");
[Link]([Link]("//
button[contains(text(),'Click for JS Confirm')]")).click();
[Link](3000);
Ranjeet kendre
// [Link]().alert().accept();
[Link]().alert().dismiss();
[Link](2000);
[Link](Text);
[Link]();
}
Example 4
package Popups;
import [Link];
import [Link];
import [Link];
import [Link];
Ranjeet kendre
public class Popup2_JS3 {
[Link]().window().maximize();
[Link]("[Link]
javascript_alerts");
[Link]([Link]("//button[contains(text(),'Click
for JS Prompt')]")).click();
[Link](2000);
Alert Text=[Link]().alert();
[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];
[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();
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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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];
[Link]("--disable-notifications");
// Javascript alert & confirmation popup
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
[Link]("[Link]
[Link](2000);
[Link]();
Example 8
package Popups;
import [Link];
import [Link];
import [Link];
import [Link];
[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]().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];
[Link]("[Link]", "/Users/ranjeetkendre/
Documents/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
Examples :
package ActionsClass;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
fi
Ranjeet kendre
import [Link];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
// Step 2
[Link]().window().maximize();
[Link]("[Link]
[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);
[Link](Text);
}
}
Ranjeet kendre
Example 2
package ActionsClass;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
// Step 2
[Link]().window().maximize();
Ranjeet kendre
[Link]("[Link]
[Link]");
[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];
// Step 2
[Link]().timeouts().implicitlyWait(120,
[Link]);
[Link]().window().maximize();
[Link]("[Link]
key_presses?");
[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];
// Step 2
[Link]().window().maximize();
[Link]("[Link]
simple_context_menu.html");
[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];
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");
// Step 2
[Link]().window().maximize();
[Link]("[Link]
drag-drop-custom/[Link]");
WebElement Source=[Link]([Link]("box3"));
WebElement dest=[Link]([Link]("box103"));
[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];
@SuppressWarnings("deprecation")
public static void main(String[] args) throws
InterruptedException {
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
// Step 2
[Link]().timeouts().implicitlyWait(120,
[Link]);
Ranjeet kendre
[Link]().window().maximize();
// [Link]("[Link]
[Link]("[Link]
WebElement input1 = [Link]([Link]("email"));
WebElement input2 = [Link]([Link]("pass"));
[Link](2000);
[Link]("Thisismyfirstjavaprogram");
// 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];
// Step 2
[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.
Example 1
package JavaScriptExecutor;
import [Link];
import [Link];
import [Link];
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
[Link]().window().maximize();
[Link]("[Link]
[Link]("[Link](0,[Link])", "");
[Link](4000);
//ScrollUp
[Link]("[Link]=0", "");
}
}
Example 3
package JavaScriptExecutor;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
Ranjeet kendre
[Link]().window().maximize();
[Link]("[Link]
// Scrollby element
[Link]("arguments[0].scrollIntoView();",
Name);
Example 4
package JavaScriptExecutor;
import [Link];
import [Link];
import [Link];
Ranjeet kendre
public class HorizontalorRightlefscroll {
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
[Link]().window().maximize();
[Link]("[Link]
[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];
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");
[Link]().window().maximize();
[Link]("[Link]
[Link](driver, Elemet);
[Link](driver, Elemet1);
[Link](driver, Elemet2);
}
public static void drawborder(WebDriver driver,
WebElement element) {
[Link]("arguments[0].[Link]='black'",elem
ent );
}
Ranjeet kendre
Example 7
package JavaScriptExecutor;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");
[Link]().window().maximize();
[Link]("[Link]
Ranjeet kendre
WebElement Username =
[Link]([Link]("email"));
WebElement Password =
[Link]([Link]("pass"));
//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];
[Link]().window().maximize();
[Link]("[Link]
WebElement Username =
[Link]([Link]("email"));
WebElement Password = [Link]([Link]("pass"));
//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];
[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");
// Step 2
[Link]().window().maximize();
[Link]("[Link]
[Link](Account).build().perform();
[Link]([Link]("ap_email")).sendKeys("velocity@[Link]");
[Link]([Link]("continue")).click();
[Link]([Link]("ap_password")).sendKeys("qwertyu");
[Link]([Link]("signInSubmit")).click();
[Link](3000);
[Link](Text);
[Link]("alert('"+Message+"')");
}
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];
[Link]("[Link]", "/Users/ranjeetkendre/Documents/
chromedriver");
[Link]().window().maximize();
[Link]("[Link]
[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);
Example 2
package WebTables;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Ranjeet kendre
import [Link];
[Link]("[Link]", "/Users/ranjeetkendre/
Downloads/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();
// Second way
// 2<=7 - True
for (int i = 2; i <= Row; i++) {//Outer loop
// 1<=3 - True
for (int j = 1; j <= Col; j++) {// inner loop
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];
[Link]("[Link]", "/Users/ranjeetkendre/
Documents/chromedriver");
[Link]().window().maximize();
[Link]("[Link]
List<WebElement> Links=[Link]([Link]("a"));
[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];
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/chromedriver");
[Link]().window().maximize();
[Link]("[Link]
List<WebElement>
Links=[Link]([Link]("a"));
[Link]([Link]());
int Brokenlinks = 0;
if(url==null || [Link]()) {
[Link]("URL is empty or null");
}
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");
}
Example 1:
package Findelement;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link]("[Link]", "/Users/ranjeetkendre/
Documents/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]());
//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];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
// Window //[Link]("[Link]",
// "C:\\Installer\\[Link]");
[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];
//Step 11
[Link]("[Link]", "/
Users/ranjeetkendre/Documents/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];
//Step 1
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
[Link]().window().maximize();
[Link]("[Link]
login");
[Link](3000);
[Link]([Link]("//a[contains(text(),'OrangeHRM,
Inc')]")).click();
[Link](2000);
Set<String>WindowID=[Link]();
//First Method
Iterator <String>It = [Link]();
String ParentWindow=[Link]();
String ChildWindow=[Link]();
[Link]("ParentWindow -->"+ParentWindow);
[Link]("ChildWindow -->"+ChildWindow);
//Second Way
String Parent=[Link](0);
String Child = [Link](1);
[Link]("ParentWindow-->"+Parent);
[Link]("ChildWindow-->"+Child);
// ArrayList<String>AL=[Link]();
[Link]().window(ChildWindow);
[Link]("ChildWindow-->"+[Link]());
[Link]();
Example 3
package WindowHandle;
import [Link];
import [Link];
import [Link];
Ranjeet kendre
import [Link];
import [Link];
//Step 1
[Link]("[Link]", "/Users/ranjeetkendre/
Documents/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
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.
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];
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;
[Link]("[Link]
auth/login");
}
package PageObject_WithDDF;
import [Link];
import [Link];
import [Link];
import [Link];
WebDriver driver;
//1.
@FindBy(xpath = "//p[@class=\"oxd-userdropdown-name\"]")
WebElement Name;
//2.
[Link]=driver;
Ranjeet kendre
[Link](driver, this);
}
//3.
boolean Time1=[Link]();
[Link](Time1);
}
}
package PageObject_WithDDF;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link]("[Link]", "/Users/
ranjeetkendre/Documents/chromedriver");
[Link]().window().maximize();
[Link]().timeouts().implicitlyWait([Link](20));
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]();
}
Ranjeet kendre
Interview Question
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
7. Can you explain the Framework which you have used in your Selenium Project?
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
In simple words, it is used to distribute your test execution on multiple platforms and
environments concurrently.
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’]
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
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.)
<2.53 – no geckodriver
3.x – geckodriver for FF
instead of creating
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
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();
54. What is the alternative to [Link]() method to open an URL using Selenium
WebDriver?
Alternative method to [Link](“url”) method is [Link](“url”)
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
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.
[Link](Text);
[Link](Index);
[Link](Value);
72. How can you nd Broken Links in a page using Selenium WebDriver?
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
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]());
}
82. How to run Selenium WebDriver Test from the command line?
Class A{
cd c
c: javac [Link]
c: java [Link]
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();
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.
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.