SlideShare a Scribd company logo
1 of 36
Selenium Webdriver
Automation Testing using
Session Objective:
● What is Automation
● Automation Tools in The Market
● What is Selenium
● Finding Elements ( Locators / Selectors )
● Basic Operations on elements
● Best Practices / Tips
Automation Testing
Automation testing, which is also known as Test Automation, is when the
QA writes scripts and uses another software to test the product. This
process involves automation of a manual process. Automation Testing is
used to re-run the test scenarios that were performed manually, quickly,
and repeatedly.
Why And When To Automate?
● Frequent regression testing
● Repeated test case Execution is required
● User Acceptance Tests
● Faster Feedback to the developers
● Reduce the Human Effort
● Test same application on multiple environments
Tools in The Market
Open Source Testing Tools
● Selenium
● Watir
● Sikuli
● FitNesse
Commercial Testing Tools
● HP Quick Test Professional
● HP Mercury WinRunner
● IBM Rational Functional Tester
● Micro Focus SilkTest
QTP and Selenium are the most used tools in the market for
software automation testing. Hence it makes sense to compare the
pros of Selenium over QTP.
Selenium QTP
Selenium is an open-source tool. QTP is a commercial tool and there is a cost
involved in each one of the licenses.
Supports mobile devices. Supports mobile devices with the help of third-party
tools.
Has capabilities to execute scripts across different
browsers.
Can run tests in specific versions of Firefox, IE, and
Chrome.
Can execute scripts on various operating systems. Works only with Windows.
Can execute tests in parallel with the use of
Selenium Grids.
QTP cannot execute tests in parallel, however
integrating QTP with QC allows testers to execute
in parallel. QC is also a commercial tool.
Introduction To Selenium
Who named Automation Testing Tool as Selenium ?
● Selenium was originally developed by Jason Huggins in 2004 as an internal
tool at ThoughtWorks.
● The name Selenium comes from a joke made by Huggins in an email,
mocking a competitor named HP Mercury, saying that you can cure mercury
poisoning by taking selenium supplements. The others that received the email
took the name and ran with it.
● Hence the Name…
Selenium is a set of tools for
cross-platform automated
testing of web application.
Selenium Supports:
● IE, Firefox, Chrome, Safari and
Other browsers.
● Windows, Linux, OS X and Other
OS’s.
● C#, Java, Ruby, Python, Perl, PHP
and Other languages.
● JUnit, RSpec, TestNG, unittest,
NUnit.
What is Selenium ?
● Selenium 2.X
○ Selenium WebDriver
○ Selenium Grid
Selenium Component
● Selenium 1.X
○ Selenium Core
○ Selenium IDE
○ Selenium RC (Remote
Control)
Selenium Component - Selenium Core :
○ It is component core Javascript library that could drive interactions with the page,
automatically rerun tests against multiple browsers.
○ Selenium Core is the foundation of Selenium Remote Control (RC) and Selenium
IDE.
Selenium Component -Selenium IDE :
○ Selenium IDE (Integrated Development Environment) is a prototyping tool for
building test scripts.
○ It is a Firefox plugin and provides an easy-to-use interface for developing
automated tests.
○ Create & Edit Test Cases & Test Suites.
○ Selenium IDE has a recording feature, which records user actions as they are
performed.
○ Exports them as a reusable script in one of many programming languages that
can be later executed.
○ Run Selenese Commands.
Selenium Component - Selenium IDE :
Selenium Component - Selenium RC (Remote Control) :
○ It is a test tool that allows you to write automated web application UI tests in any
programming language against any HTTP website using any mainstream
JavaScript-enabled browser.
○ Selenium RC comes in two parts.
i. A server which automatically launches and kills browsers, and acts as a
HTTP proxy for web requests from them.
ii. Client libraries for your favorite computer language.
Selenium Component
● Selenium RC (Remote Control):
● User creates test scripts in a desired
programming language.
● Client library (interface b/w programming
languages & the Selenium-RC Server) deports
the test commands to the selenium server.
● The Selenium RC Server acts as a "middleman"
between your Selenium commands and your
browser.
● When you begin testing, Selenium RC Server
"injects" a Javascript program called Selenium
Core into the browser.
● Selenium RC Server deciphers and converts the
test commands into JavaScript commands and
sends them to the browser.
● Browser executes the commands using
selenium core and sends results back to the
Selenium RC Server
● Selenium RC Server delivers the test results to
the client library.
Selenium Component - Selenium WebDriver :
○ Selenium WebDriver is the successor to Selenium RC which sends
commands directly to the browser and retrieves results.
○ WebDriver can support the headless execution..
○ Purely object-oriented API.
○ Can test iPhone/Android applications.
Selenium Component
Selenium webdriver architecture mainly divided
into three parts:
1. Language level bindings
2. Selenium Webdriver API
3. Drivers
Selenium Component - Selenium WebDriver :
1. Language Level Bindings : These languages in which are making an framework, will interact with
the Selenium Webdriver and work on various browsers and other devices. So we have a common
API that we use for Selenium that has a common set of commands and we have various bindings
for the different languages. So you can see there’s Java, Java, Python, Ruby, there’s also some
other bindings and new bindings can be added very easily.
2. Selenium Webdriver API : Now these bindings communicate with Selenium WebDriver API and this
API send the commands taken from language level bindings interpret it and sent it to Respective
driver. In short term API contains set of common library which allow sending command to
respective drivers.
3. Drivers : Internet Browser Specific Drivers such as IE, FF, Chrome etc. The basic idea is each one
of these drivers knows how to drive the browser that it corresponds to.
For E.g. Chrome Driver knows how to handle the low level details of chrome browser and drive it to do
things like clicking the target element, navigating the target page etc.
Selenium Component - Selenium Grid:
○ Run your tests against different browsers, operating systems, and
machines all at the same time. This will ensure that the application you
are Testing is fully compatible with a wide range of browser-O.S
combinations.
○ Save time in the execution of your test suites. If you set up Selenium
Grid to run, say, 4 tests at a time, then you would be able to finish the
whole suite around 4 times faster.
Selenium Component - Selenium Grid:
What is a Hub and Node?
● The Hub
○ The hub is the central point where you
load your tests into.
○ There should only be one hub in a grid.
○ The hub is launched only on a single
machine, say, a computer whose O.S is
Windows 7 and whose browser is FF.
○ The machine containing the hub is
where the tests will be run, but you will
see the browser being automated on
the node.
● The Nodes
○ Nodes are the Selenium instances
that will execute the tests that you
loaded on the hub.
○ There can be one or more nodes
in a grid.
○ Nodes can be launched on
multiple machines with different
platforms and browsers.
○ The machines running the nodes
need not be the same platform as
that of the hub.
Locators
Selenium uses what is called locators to find and match the elements of your page
that it needs to interact with.
The different types of locator are:
● ID
● Link Text
● CSS Selector
○ Tag and ID
○ Tag and class
○ Tag and attribute
○ Tag, class, and attribute
● Name
● XPath
● DOM (Document Object Model)
○ getElementById
○ getElementsByName
○ Dom:name
○ Dom:index
Locators
Locating by ID : The most efficient way and preferred way to locate an element on a web page is By
ID. ID will be the unique on web page which can be easily identified.
<form id="login">
<input id=”username” name="username" type="text"/>
<input id="password" name="password" type="password"/>
<input type="submit" name="signin" value="SignIn" />
</form>
WebElement item = driver.findElement(By.id("username"));
page.find_by_id(‘username’)
Locators
Locating by Name: When there is no Id to use, the next worth seeing if the desired element
has a name attribute. But make sure there the name cannot be unique all the times. If there are
multiple names, Selenium will always perform action on the first matching element.
<input id=”username” class=”uname” name="username" type="text"/>
<input id="password" name="password" type="password"/>
<input type="submit" name="signin" value="SignIn" />
WebElement locator = driver.findElement(By.name("password"));
WebElement element =driver.findElement(By.className(“uname”));
Locating by Class: The CSS class locator uses a specific class attribute to get to the first
element on a web page.
Locators
Locating by Link Text : Finding an element with link text is very simple. But make sure, there is only
one unique link on the web page. If there are multiple links with the same link text (such as repeated
header and footer menu links), in such cases Selenium will perform action on the first matching element
with link.
<a href="http://www.google.com/image1/downloads">Downloads</a>
WebElement download = driver.findElement(By.linkText("Downloads"));
Locating By Partial Link Text: In the same way as LinkText, PartialLinkText also works in the
same pattern. User can provide partial link text to locate the element.
<a href="http://www.google.com/image1/downloads">Downloads</a>
WebElement download = driver.findElement(By.PartialLinkText("Down"));
Locators
Locating by CSS Selector: When we don't have an option to choose Id or Name, we should
prefer using CSS Selectors as the best alternative. CSS Selectors are string patterns used to
identify an element based on a combination of HTML tag, id, class, and attributes.
CSS locator Examples using ID and Class attributes:
<input id=”username” class=”uname” name="username" type="text"/>
<input id="password" class=”pass” name="password" type="password"/>
<input type="submit" name="signin" value="SignIn" />
WebElement Username = driver.findElement(By.cssSelector("input#username"));
WebElement Username = driver.findElement(By.cssSelector("input.uname"));
Syntax
css=tag#id
Syntax
css=tag.class
Syntax
css=tagName[attributename=attributeValue]
Locators
Locating by CSS Selector: Using CSS Selectors, we can also locate elements with sub-strings.
They are really helpful when you are working with dynamically generated ids /classes in web page
<input id=”username” class=”uname” name="username" />
<input id="password" name="password" type="password"/>
<input type="submit" name="signin" value="SignIn" />
Following special characters are important in CSS Locators for Sub-string matches:
1. '^' symbol represents the starting text in a string.
css=input[id^='pass']
2. '$' symbol represents the ending text in a string.
css=input[id$='name']
3. '*' symbol represents contains text in a string.
css=input[id*='erna']
Locators
Locating by CSS Selector (Tag and attribute):
<input id=”username” class=”uname” name="username" type="text"/>
<input id="Passwd" class=”pass” name="pword" type="password"/>
<input type="submit" name="signin" value="SignIn" />
WebElement Username = driver.findElement(By.cssSelector("input[type=’submit’]"));
Locating by CSS Selector (Tag, class, and attribute):
WebElement Username =
driver.findElement(By.cssSelector("input#Passwd[type=’password’][name=’pword’]"));
Syntax: tagName[attributename=attributeValue]
Syntax: tagName<. Or #><value of Class or ID attribute><[attributename=attributeValue]>
Locators
Locating by DOM Selector (getElementById): The Document Object Model (DOM), in simple
terms, is the way by which HTML elements are structured.
<input id=”username” class=”uname” name="username" />
<input id="password" name="password" type="password"/>
<input type="submit" name="signin" value="SignIn" />
Syntax: document.getElementById("id of the element")
WebElement email = (WebElement) ((JavascriptExecutor) driver).executeScript("return
document.getElementById('username');");
Locators
Locating by DOM Selector (getElementsByName): The getElementById
method can access only one element at a time, as ID of an element is unique. In
case if getElementsByName method, we get an array of elements because
multiple elements can share the same name. We access the individual elements
using an index which starts at 0.
Syntax: document.getElementsByName("name")[index]
<input id=”Firstname” name="my-name" />
<input id=”Lastname” name="my-name" />
<input id="password" name="password" type="password"/>
<input type="submit" name="signin" value="SignIn" />
WebElement last = (WebElement) ((JavascriptExecutor) driver).executeScript("return
document.getElementsByName('my-name')[0];");
Locators
Locating by DOM Selector (Dom:name): This method will only apply to the element which
contains name attribute.
<form class=”my-form” name=”login”>
First name:<input type="text" name="firstname" value="lucifer">
Last name:<input type="text" name="lastname" value="Morningstar">
Password:<input name="pword" type="password"/>
</form>
Syntax: document.forms[“ form name"].elements["element name"]
WebElement Fname = (WebElement) ((JavascriptExecutor) driver).executeScript("return
document.forms['login'].elements['lucifer'];");
Locators
Locating by DOM Selector (Dom:index): This method works even when the
element (form) has no name because it uses the form's index and not its name.
Syntax: document.forms[form index].elements[element index]
<form class=”my-form” name=”login”>
First name:<input type="text" name="firstname" value="lucifer">
Last name:<input type="text" name="lastname" value="Morningstar">
Password:<input name="pword" type="password"/>
</form>
WebElement Lastname = (WebElement) ((JavascriptExecutor) driver).executeScript("return
document.forms[0].elements['1’'];");
Locators
Locating by XPATH: XPath is defined as XML path. It is one method which guarantees to locate any
element on the page using the XPath expression. But we should be very careful while forming an XPath
as it may not work if there are changes in the web application.
Syntax: Xpath=//tagname[@attribute='value']
● // : Select current node.
● Tagname: Tagname of the particular node.
● @: Select attribute.
● Attribute: Attribute name of the node.
● Value: Value of the attribute.
There are two types of XPath:
1. Absolute XPath.
2. Relative XPath .
● / : root node.
Locators
Locating by XPATH(Absolute XPath): It is the direct way to find the element, but if some
other tag added in between, then this path will no longer work. When are talking about
Absolute XPath begins with the single forward slash(/) , which means you can select the
element from the root node.
<html>
<body>
<form id=”my-form” name=”login”>
<input type="text" name="firstname" value="lucifer"/>
<input type="text" name="lastname" value="Morningstar"/>
<input name="continue" type="button" value="Clear" />
</form>
</body>
<html>
XPATH will work If the Path we defined as
firstname = driver.find_element_by_xpath("/html/body/form/input[1]")
But If there is a tag that has added between body and form as belowit won’t work
firstname = driver.find_element_by_xpath("html/body/div/form/input[1]")
Locators
Locating by XPATH(Relative Xpath): For Relative Xpath the path starts from the middle of the
HTML DOM structure. It starts with the double forward slash (//), which means it can search the element
anywhere at the webpage.
<html>
<body>
<form id=”my-form” name=”login”>
<input type="text" name="firstname" value="lucifer"/>
<input type="text" name="lastname" value="Morningstar"/>
<input name="continue" type="button" value="Clear" />
</form>
</body>
<html>
firstname = driver.find_element_by_xpath("//form/input[@name=firstname]")
firstname = driver.find_element_by_xpath("//form[@id=my-form]/input[1]")
firstname = driver.find_element_by_xpath("//input[@name=firstname]")
Basic Operations
Basic Operations on elements: Once we identify web elements using a suitable
selector strategy, we will need to interact with the elements. The methods we will be using
depends on the type of WebElement we interact with.
For example, we can sendKeys() to a text field, click() on a link etc. Below given commands
are commonly used commands of selenium webdriver to use in automation process of any
software web application.
● Command To Open URL In Browser:
driver.navigate().to("https://www.facebook.com/");
driver.navigate().back();
driver.navigate().forward();
Basic Operations
● Store text of targeted element in variable:
String dropdown = driver.findElement(By.tagName("select")).getText();
● Typing text in text box or text area.
driver.findElement(By.id("my-name")).sendKeys("My First Name");
● Clicking on any element or button of webpage:
driver.findElement(By.id("submitButton")).click();
● Selenium WebDriver Assertions.
Assert.assertEquals(actual, expected);
Assert.assertNotEquals(actual, expected);
● Submit() method to submit form
driver.findElement(By.xpath("//input[@name='Company']")).submit();
Basic Operations
● Handling Alert, Confirmation and Prompts Popups:
String myalert = driver.switchTo().alert().getText();
driver.switchTo().alert().accept();
driver.switchTo().alert().dismiss();
driver.switchTo().alert().sendKeys("This Is Lucifer");
● Implicit wait in webdriver
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
● Explicit wait in webdriver with WebDriver
WebDriverWait wait = new WebDriverWait(driver, 20);
These were the basic operation that we do on the webpage, operations also Handling Multiple
Windows, Handling Iframes, Fileupload, Datepicker etc.
Best Practise / TIPS
● Understand the application being tested:
○ Business Model
○ Application Flow
● Good Automation means good manual test case:
It is always advisable to first write the test case in manual form. One should run this test case
manually at least once to clearly decide what objects need to be identified and what will be the flow
of navigation. Ask questions with manual testers.
● Know The Selenium methods well
● Know The Selectors well
Preferred selector order: id > name > css > xpath
● More you write more you learn
Thank You
Pankaj Biswas
Now we know Basics of Automation testing
using Selenium Webdriver

More Related Content

What's hot

An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriverAnuraj S.L
 
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...Simplilearn
 
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesVijay Rangaiah
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with seleniumTzirla Rozental
 
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...Simplilearn
 
Test Automation Using Selenium
Test Automation Using SeleniumTest Automation Using Selenium
Test Automation Using SeleniumNikhil Kapoor
 
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...Edureka!
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using SeleniumNaresh Chintalcheru
 

What's hot (20)

Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
 
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
 
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering Colleges
 
SELENIUM PPT.pdf
SELENIUM PPT.pdfSELENIUM PPT.pdf
SELENIUM PPT.pdf
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Selenium Concepts
Selenium ConceptsSelenium Concepts
Selenium Concepts
 
Selenium WebDriver training
Selenium WebDriver trainingSelenium WebDriver training
Selenium WebDriver training
 
Selenium
SeleniumSelenium
Selenium
 
Test automation using selenium
Test automation using seleniumTest automation using selenium
Test automation using selenium
 
Selenium
SeleniumSelenium
Selenium
 
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
 
Test Automation Using Selenium
Test Automation Using SeleniumTest Automation Using Selenium
Test Automation Using Selenium
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
 
Selenium Automation Framework
Selenium Automation  FrameworkSelenium Automation  Framework
Selenium Automation Framework
 
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 

Similar to Automation Testing using Selenium Webdriver

A Simple Guide to Selenium Software Testing
A Simple Guide to Selenium Software TestingA Simple Guide to Selenium Software Testing
A Simple Guide to Selenium Software TestingCalidad Infotech
 
Demystifying Selenium framework
Demystifying Selenium frameworkDemystifying Selenium framework
Demystifying Selenium frameworkkunalgate125
 
Selenium Basics by Quontra Solutions
Selenium Basics by Quontra SolutionsSelenium Basics by Quontra Solutions
Selenium Basics by Quontra SolutionsQUONTRASOLUTIONS
 
selenium-webdriver-interview-questions.pdf
selenium-webdriver-interview-questions.pdfselenium-webdriver-interview-questions.pdf
selenium-webdriver-interview-questions.pdfAnuragMourya8
 
Python selenium
Python seleniumPython selenium
Python seleniumDucat
 
Selenium PPT 2.pptx
Selenium PPT 2.pptxSelenium PPT 2.pptx
Selenium PPT 2.pptxssusere4c6aa
 
Selenium Webdriver Interview Questions
Selenium Webdriver Interview QuestionsSelenium Webdriver Interview Questions
Selenium Webdriver Interview QuestionsJai Singh
 
Basics of Selenium IDE,Core, Remote Control
Basics of Selenium IDE,Core, Remote ControlBasics of Selenium IDE,Core, Remote Control
Basics of Selenium IDE,Core, Remote Controlusha kannappan
 
Interview Question & Answers for Selenium Freshers | LearningSlot
Interview Question & Answers for Selenium Freshers | LearningSlotInterview Question & Answers for Selenium Freshers | LearningSlot
Interview Question & Answers for Selenium Freshers | LearningSlotLearning Slot
 
Selenium online training nareshit
Selenium online training nareshitSelenium online training nareshit
Selenium online training nareshitAvinashNareshIT
 

Similar to Automation Testing using Selenium Webdriver (20)

A Simple Guide to Selenium Software Testing
A Simple Guide to Selenium Software TestingA Simple Guide to Selenium Software Testing
A Simple Guide to Selenium Software Testing
 
Demystifying Selenium framework
Demystifying Selenium frameworkDemystifying Selenium framework
Demystifying Selenium framework
 
Selenium Basics by Quontra Solutions
Selenium Basics by Quontra SolutionsSelenium Basics by Quontra Solutions
Selenium Basics by Quontra Solutions
 
Selenium.pptx
Selenium.pptxSelenium.pptx
Selenium.pptx
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
selenium-webdriver-interview-questions.pdf
selenium-webdriver-interview-questions.pdfselenium-webdriver-interview-questions.pdf
selenium-webdriver-interview-questions.pdf
 
Python selenium
Python seleniumPython selenium
Python selenium
 
Selenium
SeleniumSelenium
Selenium
 
Selenium PPT 2.pptx
Selenium PPT 2.pptxSelenium PPT 2.pptx
Selenium PPT 2.pptx
 
Selenium Webdriver Interview Questions
Selenium Webdriver Interview QuestionsSelenium Webdriver Interview Questions
Selenium Webdriver Interview Questions
 
Selenium&amp;scrapy
Selenium&amp;scrapySelenium&amp;scrapy
Selenium&amp;scrapy
 
Selenium Primer
Selenium PrimerSelenium Primer
Selenium Primer
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
 
BCS Selenium Workshop
BCS Selenium WorkshopBCS Selenium Workshop
BCS Selenium Workshop
 
Selenium
SeleniumSelenium
Selenium
 
Basics of Selenium IDE,Core, Remote Control
Basics of Selenium IDE,Core, Remote ControlBasics of Selenium IDE,Core, Remote Control
Basics of Selenium IDE,Core, Remote Control
 
Interview Question & Answers for Selenium Freshers | LearningSlot
Interview Question & Answers for Selenium Freshers | LearningSlotInterview Question & Answers for Selenium Freshers | LearningSlot
Interview Question & Answers for Selenium Freshers | LearningSlot
 
Selenium
SeleniumSelenium
Selenium
 
Selenium online training nareshit
Selenium online training nareshitSelenium online training nareshit
Selenium online training nareshit
 

Recently uploaded

What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 

Recently uploaded (20)

What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 

Automation Testing using Selenium Webdriver

  • 2. Session Objective: ● What is Automation ● Automation Tools in The Market ● What is Selenium ● Finding Elements ( Locators / Selectors ) ● Basic Operations on elements ● Best Practices / Tips
  • 3. Automation Testing Automation testing, which is also known as Test Automation, is when the QA writes scripts and uses another software to test the product. This process involves automation of a manual process. Automation Testing is used to re-run the test scenarios that were performed manually, quickly, and repeatedly. Why And When To Automate? ● Frequent regression testing ● Repeated test case Execution is required ● User Acceptance Tests ● Faster Feedback to the developers ● Reduce the Human Effort ● Test same application on multiple environments
  • 4. Tools in The Market Open Source Testing Tools ● Selenium ● Watir ● Sikuli ● FitNesse Commercial Testing Tools ● HP Quick Test Professional ● HP Mercury WinRunner ● IBM Rational Functional Tester ● Micro Focus SilkTest
  • 5. QTP and Selenium are the most used tools in the market for software automation testing. Hence it makes sense to compare the pros of Selenium over QTP. Selenium QTP Selenium is an open-source tool. QTP is a commercial tool and there is a cost involved in each one of the licenses. Supports mobile devices. Supports mobile devices with the help of third-party tools. Has capabilities to execute scripts across different browsers. Can run tests in specific versions of Firefox, IE, and Chrome. Can execute scripts on various operating systems. Works only with Windows. Can execute tests in parallel with the use of Selenium Grids. QTP cannot execute tests in parallel, however integrating QTP with QC allows testers to execute in parallel. QC is also a commercial tool.
  • 6. Introduction To Selenium Who named Automation Testing Tool as Selenium ? ● Selenium was originally developed by Jason Huggins in 2004 as an internal tool at ThoughtWorks. ● The name Selenium comes from a joke made by Huggins in an email, mocking a competitor named HP Mercury, saying that you can cure mercury poisoning by taking selenium supplements. The others that received the email took the name and ran with it. ● Hence the Name…
  • 7. Selenium is a set of tools for cross-platform automated testing of web application. Selenium Supports: ● IE, Firefox, Chrome, Safari and Other browsers. ● Windows, Linux, OS X and Other OS’s. ● C#, Java, Ruby, Python, Perl, PHP and Other languages. ● JUnit, RSpec, TestNG, unittest, NUnit. What is Selenium ?
  • 8. ● Selenium 2.X ○ Selenium WebDriver ○ Selenium Grid Selenium Component ● Selenium 1.X ○ Selenium Core ○ Selenium IDE ○ Selenium RC (Remote Control)
  • 9. Selenium Component - Selenium Core : ○ It is component core Javascript library that could drive interactions with the page, automatically rerun tests against multiple browsers. ○ Selenium Core is the foundation of Selenium Remote Control (RC) and Selenium IDE.
  • 10. Selenium Component -Selenium IDE : ○ Selenium IDE (Integrated Development Environment) is a prototyping tool for building test scripts. ○ It is a Firefox plugin and provides an easy-to-use interface for developing automated tests. ○ Create & Edit Test Cases & Test Suites. ○ Selenium IDE has a recording feature, which records user actions as they are performed. ○ Exports them as a reusable script in one of many programming languages that can be later executed. ○ Run Selenese Commands. Selenium Component - Selenium IDE :
  • 11. Selenium Component - Selenium RC (Remote Control) : ○ It is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser. ○ Selenium RC comes in two parts. i. A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them. ii. Client libraries for your favorite computer language.
  • 12. Selenium Component ● Selenium RC (Remote Control): ● User creates test scripts in a desired programming language. ● Client library (interface b/w programming languages & the Selenium-RC Server) deports the test commands to the selenium server. ● The Selenium RC Server acts as a "middleman" between your Selenium commands and your browser. ● When you begin testing, Selenium RC Server "injects" a Javascript program called Selenium Core into the browser. ● Selenium RC Server deciphers and converts the test commands into JavaScript commands and sends them to the browser. ● Browser executes the commands using selenium core and sends results back to the Selenium RC Server ● Selenium RC Server delivers the test results to the client library.
  • 13. Selenium Component - Selenium WebDriver : ○ Selenium WebDriver is the successor to Selenium RC which sends commands directly to the browser and retrieves results. ○ WebDriver can support the headless execution.. ○ Purely object-oriented API. ○ Can test iPhone/Android applications.
  • 14. Selenium Component Selenium webdriver architecture mainly divided into three parts: 1. Language level bindings 2. Selenium Webdriver API 3. Drivers
  • 15. Selenium Component - Selenium WebDriver : 1. Language Level Bindings : These languages in which are making an framework, will interact with the Selenium Webdriver and work on various browsers and other devices. So we have a common API that we use for Selenium that has a common set of commands and we have various bindings for the different languages. So you can see there’s Java, Java, Python, Ruby, there’s also some other bindings and new bindings can be added very easily. 2. Selenium Webdriver API : Now these bindings communicate with Selenium WebDriver API and this API send the commands taken from language level bindings interpret it and sent it to Respective driver. In short term API contains set of common library which allow sending command to respective drivers. 3. Drivers : Internet Browser Specific Drivers such as IE, FF, Chrome etc. The basic idea is each one of these drivers knows how to drive the browser that it corresponds to. For E.g. Chrome Driver knows how to handle the low level details of chrome browser and drive it to do things like clicking the target element, navigating the target page etc.
  • 16. Selenium Component - Selenium Grid: ○ Run your tests against different browsers, operating systems, and machines all at the same time. This will ensure that the application you are Testing is fully compatible with a wide range of browser-O.S combinations. ○ Save time in the execution of your test suites. If you set up Selenium Grid to run, say, 4 tests at a time, then you would be able to finish the whole suite around 4 times faster.
  • 17. Selenium Component - Selenium Grid: What is a Hub and Node? ● The Hub ○ The hub is the central point where you load your tests into. ○ There should only be one hub in a grid. ○ The hub is launched only on a single machine, say, a computer whose O.S is Windows 7 and whose browser is FF. ○ The machine containing the hub is where the tests will be run, but you will see the browser being automated on the node. ● The Nodes ○ Nodes are the Selenium instances that will execute the tests that you loaded on the hub. ○ There can be one or more nodes in a grid. ○ Nodes can be launched on multiple machines with different platforms and browsers. ○ The machines running the nodes need not be the same platform as that of the hub.
  • 18. Locators Selenium uses what is called locators to find and match the elements of your page that it needs to interact with. The different types of locator are: ● ID ● Link Text ● CSS Selector ○ Tag and ID ○ Tag and class ○ Tag and attribute ○ Tag, class, and attribute ● Name ● XPath ● DOM (Document Object Model) ○ getElementById ○ getElementsByName ○ Dom:name ○ Dom:index
  • 19. Locators Locating by ID : The most efficient way and preferred way to locate an element on a web page is By ID. ID will be the unique on web page which can be easily identified. <form id="login"> <input id=”username” name="username" type="text"/> <input id="password" name="password" type="password"/> <input type="submit" name="signin" value="SignIn" /> </form> WebElement item = driver.findElement(By.id("username")); page.find_by_id(‘username’)
  • 20. Locators Locating by Name: When there is no Id to use, the next worth seeing if the desired element has a name attribute. But make sure there the name cannot be unique all the times. If there are multiple names, Selenium will always perform action on the first matching element. <input id=”username” class=”uname” name="username" type="text"/> <input id="password" name="password" type="password"/> <input type="submit" name="signin" value="SignIn" /> WebElement locator = driver.findElement(By.name("password")); WebElement element =driver.findElement(By.className(“uname”)); Locating by Class: The CSS class locator uses a specific class attribute to get to the first element on a web page.
  • 21. Locators Locating by Link Text : Finding an element with link text is very simple. But make sure, there is only one unique link on the web page. If there are multiple links with the same link text (such as repeated header and footer menu links), in such cases Selenium will perform action on the first matching element with link. <a href="http://www.google.com/image1/downloads">Downloads</a> WebElement download = driver.findElement(By.linkText("Downloads")); Locating By Partial Link Text: In the same way as LinkText, PartialLinkText also works in the same pattern. User can provide partial link text to locate the element. <a href="http://www.google.com/image1/downloads">Downloads</a> WebElement download = driver.findElement(By.PartialLinkText("Down"));
  • 22. Locators Locating by CSS Selector: When we don't have an option to choose Id or Name, we should prefer using CSS Selectors as the best alternative. CSS Selectors are string patterns used to identify an element based on a combination of HTML tag, id, class, and attributes. CSS locator Examples using ID and Class attributes: <input id=”username” class=”uname” name="username" type="text"/> <input id="password" class=”pass” name="password" type="password"/> <input type="submit" name="signin" value="SignIn" /> WebElement Username = driver.findElement(By.cssSelector("input#username")); WebElement Username = driver.findElement(By.cssSelector("input.uname")); Syntax css=tag#id Syntax css=tag.class Syntax css=tagName[attributename=attributeValue]
  • 23. Locators Locating by CSS Selector: Using CSS Selectors, we can also locate elements with sub-strings. They are really helpful when you are working with dynamically generated ids /classes in web page <input id=”username” class=”uname” name="username" /> <input id="password" name="password" type="password"/> <input type="submit" name="signin" value="SignIn" /> Following special characters are important in CSS Locators for Sub-string matches: 1. '^' symbol represents the starting text in a string. css=input[id^='pass'] 2. '$' symbol represents the ending text in a string. css=input[id$='name'] 3. '*' symbol represents contains text in a string. css=input[id*='erna']
  • 24. Locators Locating by CSS Selector (Tag and attribute): <input id=”username” class=”uname” name="username" type="text"/> <input id="Passwd" class=”pass” name="pword" type="password"/> <input type="submit" name="signin" value="SignIn" /> WebElement Username = driver.findElement(By.cssSelector("input[type=’submit’]")); Locating by CSS Selector (Tag, class, and attribute): WebElement Username = driver.findElement(By.cssSelector("input#Passwd[type=’password’][name=’pword’]")); Syntax: tagName[attributename=attributeValue] Syntax: tagName<. Or #><value of Class or ID attribute><[attributename=attributeValue]>
  • 25. Locators Locating by DOM Selector (getElementById): The Document Object Model (DOM), in simple terms, is the way by which HTML elements are structured. <input id=”username” class=”uname” name="username" /> <input id="password" name="password" type="password"/> <input type="submit" name="signin" value="SignIn" /> Syntax: document.getElementById("id of the element") WebElement email = (WebElement) ((JavascriptExecutor) driver).executeScript("return document.getElementById('username');");
  • 26. Locators Locating by DOM Selector (getElementsByName): The getElementById method can access only one element at a time, as ID of an element is unique. In case if getElementsByName method, we get an array of elements because multiple elements can share the same name. We access the individual elements using an index which starts at 0. Syntax: document.getElementsByName("name")[index] <input id=”Firstname” name="my-name" /> <input id=”Lastname” name="my-name" /> <input id="password" name="password" type="password"/> <input type="submit" name="signin" value="SignIn" /> WebElement last = (WebElement) ((JavascriptExecutor) driver).executeScript("return document.getElementsByName('my-name')[0];");
  • 27. Locators Locating by DOM Selector (Dom:name): This method will only apply to the element which contains name attribute. <form class=”my-form” name=”login”> First name:<input type="text" name="firstname" value="lucifer"> Last name:<input type="text" name="lastname" value="Morningstar"> Password:<input name="pword" type="password"/> </form> Syntax: document.forms[“ form name"].elements["element name"] WebElement Fname = (WebElement) ((JavascriptExecutor) driver).executeScript("return document.forms['login'].elements['lucifer'];");
  • 28. Locators Locating by DOM Selector (Dom:index): This method works even when the element (form) has no name because it uses the form's index and not its name. Syntax: document.forms[form index].elements[element index] <form class=”my-form” name=”login”> First name:<input type="text" name="firstname" value="lucifer"> Last name:<input type="text" name="lastname" value="Morningstar"> Password:<input name="pword" type="password"/> </form> WebElement Lastname = (WebElement) ((JavascriptExecutor) driver).executeScript("return document.forms[0].elements['1’'];");
  • 29. Locators Locating by XPATH: XPath is defined as XML path. It is one method which guarantees to locate any element on the page using the XPath expression. But we should be very careful while forming an XPath as it may not work if there are changes in the web application. Syntax: Xpath=//tagname[@attribute='value'] ● // : Select current node. ● Tagname: Tagname of the particular node. ● @: Select attribute. ● Attribute: Attribute name of the node. ● Value: Value of the attribute. There are two types of XPath: 1. Absolute XPath. 2. Relative XPath . ● / : root node.
  • 30. Locators Locating by XPATH(Absolute XPath): It is the direct way to find the element, but if some other tag added in between, then this path will no longer work. When are talking about Absolute XPath begins with the single forward slash(/) , which means you can select the element from the root node. <html> <body> <form id=”my-form” name=”login”> <input type="text" name="firstname" value="lucifer"/> <input type="text" name="lastname" value="Morningstar"/> <input name="continue" type="button" value="Clear" /> </form> </body> <html> XPATH will work If the Path we defined as firstname = driver.find_element_by_xpath("/html/body/form/input[1]") But If there is a tag that has added between body and form as belowit won’t work firstname = driver.find_element_by_xpath("html/body/div/form/input[1]")
  • 31. Locators Locating by XPATH(Relative Xpath): For Relative Xpath the path starts from the middle of the HTML DOM structure. It starts with the double forward slash (//), which means it can search the element anywhere at the webpage. <html> <body> <form id=”my-form” name=”login”> <input type="text" name="firstname" value="lucifer"/> <input type="text" name="lastname" value="Morningstar"/> <input name="continue" type="button" value="Clear" /> </form> </body> <html> firstname = driver.find_element_by_xpath("//form/input[@name=firstname]") firstname = driver.find_element_by_xpath("//form[@id=my-form]/input[1]") firstname = driver.find_element_by_xpath("//input[@name=firstname]")
  • 32. Basic Operations Basic Operations on elements: Once we identify web elements using a suitable selector strategy, we will need to interact with the elements. The methods we will be using depends on the type of WebElement we interact with. For example, we can sendKeys() to a text field, click() on a link etc. Below given commands are commonly used commands of selenium webdriver to use in automation process of any software web application. ● Command To Open URL In Browser: driver.navigate().to("https://www.facebook.com/"); driver.navigate().back(); driver.navigate().forward();
  • 33. Basic Operations ● Store text of targeted element in variable: String dropdown = driver.findElement(By.tagName("select")).getText(); ● Typing text in text box or text area. driver.findElement(By.id("my-name")).sendKeys("My First Name"); ● Clicking on any element or button of webpage: driver.findElement(By.id("submitButton")).click(); ● Selenium WebDriver Assertions. Assert.assertEquals(actual, expected); Assert.assertNotEquals(actual, expected); ● Submit() method to submit form driver.findElement(By.xpath("//input[@name='Company']")).submit();
  • 34. Basic Operations ● Handling Alert, Confirmation and Prompts Popups: String myalert = driver.switchTo().alert().getText(); driver.switchTo().alert().accept(); driver.switchTo().alert().dismiss(); driver.switchTo().alert().sendKeys("This Is Lucifer"); ● Implicit wait in webdriver driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); ● Explicit wait in webdriver with WebDriver WebDriverWait wait = new WebDriverWait(driver, 20); These were the basic operation that we do on the webpage, operations also Handling Multiple Windows, Handling Iframes, Fileupload, Datepicker etc.
  • 35. Best Practise / TIPS ● Understand the application being tested: ○ Business Model ○ Application Flow ● Good Automation means good manual test case: It is always advisable to first write the test case in manual form. One should run this test case manually at least once to clearly decide what objects need to be identified and what will be the flow of navigation. Ask questions with manual testers. ● Know The Selenium methods well ● Know The Selectors well Preferred selector order: id > name > css > xpath ● More you write more you learn
  • 36. Thank You Pankaj Biswas Now we know Basics of Automation testing using Selenium Webdriver