In this quality assurance training session, you will learn Selenium WebDriver Testing. Topics covered in this course are:
• Overview of Selenium WebDriver
• Get Selenium WebDriver Java
• Selenium – JAVA Configuration
• WebDriver in Different Browsers
• Open Application
• Browser Settings
• Locating Elements
• Object Identification Methods
• Locator ID, Name
• Locators –LinkText, partialLinkText, CSS, CSS
• Accessing different objects in application
• Switch Window
• Wait in WebDriver
• Verifications
• WebTable
To know more, visit this link: https://www.mindsmapped.com/courses/quality-assurance/software-testing-quality-assurance-qa-training-with-hands-on-exercises/
2. Page 2Classification: Restricted
Agenda
• Overview of Selenium WebDriver
• Get Selenium WebDriver Java
• Selenium – JAVA Configuration
• WebDriver in Different Browsers
• Open Application
• Browser Settings
• Locating Elements
• Object Identification Methods
• Locator ID, Name
• Locators –LinkText, partialLinkText, CSS, CSS
• Accessing different objects in application
• Switch Window
• Wait in WebDriver
• Verifications
• WebTable
3. Page 3Classification: Restricted
• Selenium WebDriver - is latest version of Selenium (Selenium 2/3)
• WebDriver is a compact Object Oriented API when compared to
Selenium1.0
• It drives the browser much more effectively
• WebDriver will support following programming languages
• Java, C#, Ruby, Python, JavaScript (Node.js)
• Selenium WebDriver will support following browsers
• Google Chrome, Internet Explorer, Firefox, Safari, Opera, Edge
(Win 10)
Overview of Selenium WebDriver
4. Page 4Classification: Restricted
• Selenium WebDriver is available from Selenium official website
(http://www.seleniumhq.org)
• It is an open source and free software
• Source code is available in
https://github.com/SeleniumHQ/selenium
Get Selenium WebDriver Java
5. Page 5Classification: Restricted
• Install Java JDK (1.8 is recommended)
• Install Java IDE (Eclipse Kepler)
• Download Selenium Java jar files
(http://www.seleniumhq.org/download/)
• Install and configure browsers in the system
• Download required browser driver
Selenium – JAVA configuration
6. Page 6Classification: Restricted
• Open Eclipse with Workspace
• Create a new Java project (As
mentioned in the Core Java
session)
• Right click on the project and go
to Build Path -> Configure Build
Path
Selenium – JAVA Project creation
7. Page 7Classification: Restricted
Selenium – JAVA Project creation
7
• Go to Libraries Tab and click on Add External Jars… to select selenium Jar
files
• Select all jars which are download then click on Open and click on OK
8. Page 8Classification: Restricted
WebDriver in Different Browsers
8
• Google Chrome
• Mozilla Firefox
• MS Internet Explorer
• Safari
WebDriver driver;
System.setProperty("webdriver.chrome.driver", “<<Path of
chromedriver.exe>>");
driver = new ChromeDriver();
System.setProperty("webdriver.gecko.driver", “<<path of
geckodriver.exe>>");
driver = new FirefoxDriver();
System.setProperty(“webdriver.ie.driver ",“<<Path of
IEDriverServer.exe>>");
driver = new InternetExplorerDriver();
driver = new SafariDriver();
9. Page 9Classification: Restricted
• MS Edge(Windows 10)
System.setProperty("webdriver.edge.driver", “<<path of
MicrosoftWebDriver.exe“>>);
driver = new EdgeDriver();
WebDriver in Different Browsers
10. Page 10Classification: Restricted
• Pre-requisites to open a URL
• Browser need to be installed
• Browser driver need to upgrade based on browser version
• Browser zoom level should be 100%
• Syntax to open url is,
driver.get(“http://google.com/”);
Open Application
11. Page 11Classification: Restricted
• For Internet Explorer,
• On IE 7 or higher on Windows, must set the Protected Mode
settings for each zone to be the same value.
• The value can be on or off, as long as it is the same for every
zone.
Browser Settings
12. Page 12Classification: Restricted
• To set the Protected Mode settings,
choose "Internet Options..." from
the Tools menu, and click on the
Security tab.
• For each zone, there will be a check
box at the bottom of the tab
labeled "Enable Protected Mode"
Browser Settings
13. Page 13Classification: Restricted
• Locating elements in WebDriver is done by using the
findElement(By.locator()) method
Variati
on
Description Sample
By.id
locates elements by the
value of their "id" attribute
findElement(By.id("someId
"))
By.nam
e
locates elements by the
value of the "name"
attribute
findElement(By.name("so
meName"))
By.linkT
ext
finds a link element by the
exact text it displays
findElement(By.linkText("R
EGISTRATION"))
By.parti
alLinkTe
xt
locates elements that
contain the given link text
findElement(By.partialLink
Text("REG"))
By.cssS
elector
finds elements based on the
driver's underlying CSS
Selector engine
findElement(By.cssSelector
("input#email"))
Locating Elements
14. Page 14Classification: Restricted
Variati
on
Description Sample
By.class
Name
finds elements based on the
value of the "class" attribute
findElement(By.className
("someClassName"))
By.tagN
ame
locates elements by their tag
name
findElement(By.tagName("
div"))
By.xpat
h
locates elements via XPath
findElement(By.xpath(“//in
put[@id=‘username’]"))
Locating Elements
15. Page 15Classification: Restricted
IE Developer tool:
• Press F12 to open developer tool
• Click on the arrow key to select the object to get the property
• Click on Attribute to get different object attributes
Object Identification Methods
16. Page 16Classification: Restricted
Chrome: Inspect element
• Right click on the object you want identify and select Inspect element
option
• Find different properties available with the object or right click on
highlighted code and select copy CSS path or Copy Xpath
Object Identification Methods
17. Page 17Classification: Restricted
Firefox: Inspect element
• Right click on the object you want identify and select Inspect element
(Q) option
• Find different properties available with the object
Firebug (Firefox add-on)
• Firebug has different methods to select the object properties
• Find for the code
• Select properties for DOM
• Copy Xpath
• Copy CSS file
Object Identification Methods
18. Page 18Classification: Restricted
Selenium IDE
• Enter the object property Target column and click on Find button to
check the object
• Click on Select and highlight the object to get the object properties
Object Identification Methods
19. Page 19Classification: Restricted
The Id strategy looks for an element in the page having an id attribute
corresponding to the specified pattern. <label id="my_id" /> will be matched
by a locator like id=my_id or just my_id
driver.findElement(By.id("my_id"));
Locator ID
20. Page 20Classification: Restricted
Is the Id strategy, but on the name attribute
<html>
<body>
<div id="pancakes">
<button type="button" name="pancake“
value="Blueberry">Blueberry</button>
</div>
</body>
</html>
driver.findElement(By.name("pancake"));
Locator Name
21. Page 21Classification: Restricted
select links only and selects the anchor element containing the specified
text: link=The text of the link
<a href="http://www.phptravels.net/offers.html" target="_self">
Offers</a>
driver.findElement(By.linkText("Offers"));
Locators -LinkText
22. Page 22Classification: Restricted
select links only and selects the anchor element containing the
specified text: link=The text of the link and take the part of the link
<a
href="mercuryunderconst.php?osCsid=af0ce02d7eb466b9a4ec43f
2d5273db9">Car Rentals</a>
driver.findElement(By.partialLinkText("Ren"));
Locators -partialLinkText
23. Page 23Classification: Restricted
CSS Selectors are string patterns used to identify an element based
on a combination of HTML tag, id, class, and attributes. Locating by
CSS Selector is more complicated than the previous methods, but it
is the most common locating strategy of advanced Selenium users
because it can access even those elements that have no ID or
name.
driver.findElement(By.cssSelector("input #usernme"));
Locators -CSS
24. Page 24Classification: Restricted
XPath is the standard navigation tool for XML; and an HTML
document is also an XML document (xHTML). XPath is used
everywhere where there is XML.
It can access almost any element, even those without class, name,
or id attributes.
It is the most complicated method of identifying elements because
of too many different rules and considerations.
driver.findElement(By.xpath("//input[@id = 'usernme']"));
Locators -Xpath
25. Page 25Classification: Restricted
Dropdown, Multi select
Declare the drop-down element
Select elmDrp=new Select
(WebElement)
elmDrp.selectByVisibleText(”text
”)
deselectByVisibleText()
selectByIndex()
deselectByIndex()
isMultiple()
deselectAll()
Text Fields
.sendKeys(“value”)
.clear()
Radio button, Link
.click()
Checkbox
.click()
.isSelected()
Accessing Different Objects in Application
26. Page 26Classification: Restricted
Switching Between Frames
driver.switchTo().frame(“FrameName”)
Switching Between Pop-up Windows
driver.switchTo().alert()
Get pop-up message
driver.switchTo().alert().getText()
Click on OK on pop-up
driver.switchTo().alert().accept()
Switch Window
27. Page 27Classification: Restricted
Implicit wait
Used to set the default waiting time throughout the program
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Explicit wait
used to set the waiting time for a particular instance only
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.n
ame("userName")));
Wait in WebDriver
29. Page 29Classification: Restricted
To get items from a table we can create object by table xpath
To get value from different row and column create dynamic object
run time
String xpath = "//table[@width="270"]/tbody/tr[" + row +
"]/td[" + col + "]";
driver.findElement(By.xpath(xpath)).getText();
Can create table xpath with some unique property
WebTable