Techniques	and	tricks	in	using	locators
-Sriram
Agenda
Ø What	locators	are?
Ø Different	types	of	locators
Ø Walkthrough	on	css selectors	and	xpath
Ø Demo
What	actually	are	locators	?
Different	types	of	locators
Ø ID
Ø Name
Ø Link	text
Ø Partial	Link	text
Ø Tag	Name
Ø Class	name
Ø Css
Ø Xpath
What	is	css selector
What	is	xpath
HTML
BODY
DIV DIV DIV
DIV A A SPAN TABLE
TR
TD
TD
TD
TR
TD
TD
TD
class	=	banner id=	banner
Attribute	
href=“in.bookmyshow.com/f
avicon”
IMG
Attribute	
href
Identify	Elements	with	class	attribute
HTML
BODY
DIV DIV DIV
DIV A A SPAN TABLE
TR
TD
TD
TD
TR
TD
TD
TD
class	=	banner id=	banner
Attribute	
href=“in.bookmyshow.com/f
avicon”
IMG
Attribute	
href
driver.findElement(By.cssSelector(”.banner"));
driver.findElement(By.xpath(”//div[@class=‘banner’"));
Identify	Elements	with	ID	attribute
HTML
BODY
DIV DIV DIV
DIV A A SPAN TABLE
TR
TD
TD
TD
TR
TD
TD
TD
class	=	banner id=	banner
Attribute	
href=“in.bookmyshow.com/f
avicon”
IMG
Attribute	
href
driver.findElement(By.cssSelector(”#banner"));
driver.findElement(By.xpath(”//div[@id=‘banner’]"));
Identify	Elements	by	its	type
HTML
BODY
DIV DIV DIV
DIV A A SPAN TABLE
TR
TD
TD
TD
TR
TD
TD
TD
class	=	banner id=	banner
Attribute	
href=“in.bookmyshow.com/f
avicon”
IMG
Attribute	
href
driver.findElements(By.cssSelector(”div"));
driver.findElements(By.xpath(”//div"));
Identify	Elements	with	parent	and	child	element	
types
HTML
BODY
DIV DIV DIV
DIV A A SPAN TABLE
TR
TD
TD
TD
TR
TD
TD
TD
class	=	banner id=	banner
Attribute	
href=“in.bookmyshow.com/f
avicon”
IMG
Attribute	
href
driver.findElements(By.cssSelector(”tr >	td"));
driver.findElements(By.xpath(”//tr/td"));
Identify	Elements	having	a	specific	attribute
HTML
BODY
DIV DIV DIV
DIV A A SPAN TABLE
TR
TD
TD
TD
TR
TD
TD
TD
class	=	banner id=	banner
Attribute	
href=“in.bookmyshow.com/f
avicon”
IMG
Attribute	
href
driver.findElements(By.cssSelector(”[href]"));
driver.findElements(By.xpath(”//*[@href]"));
Identify	Elements	by	what	attribute	value	starts
with
HTML
BODY
DIV DIV DIV
DIV A A SPAN
class	=	banner id=	banner
Attribute	
href=“in.bookmyshow.com/f
avicon”
IMG
Attribute	
href
driver.findElement(By.cssSelector(”a[href^=‘in’]"));
driver.findElement(By.xpath(”//a[starts-with(@href,’in’)]"));
Identify	Elements	by	what	attribute	value	ends
with
HTML
BODY
DIV DIV DIV
DIV A A SPAN
class	=	banner id=	banner
Attribute	
href=“in.bookmyshow.com/f
avicon”
IMG
Attribute	
href
driver.findElement(By.cssSelector(”a[href$=‘favicon’]"));
driver.findElement(By.xpath(”//a[ends-with(@href,‘favicon’)]"));
Identify	Elements	by	what	attribute	value	contains
HTML
BODY
DIV DIV DIV
DIV A A SPAN
class	=	banner id=	banner
Attribute	
href=“in.bookmyshow.com/f
avicon”
IMG
Attribute	
href
driver.findElement(By.cssSelector(”a[href*=‘bookmyshow’]"));
driver.findElement(By.xpath(”//a[contains(@href,‘bookmyshow’]"));
Identify	2nd child	of	a	parent	element
HTML
BODY
DIV DIV DIV
DIV A A SPAN TABLE
TR
TD
TD
TD
TR
TD
TD
TD
class	=	banner id=	banner
Attribute	
href=“in.bookmyshow.com/f
avicon”
IMG
Attribute	
href
driver.findElements(By.cssSelector(”td:nth-child(2)"));
driver.findElements(By.xpath(”//td[2]"));
Techniques and tricks in using locators with selenium
Techniques and tricks in using locators with selenium
https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference
http://www.w3schools.com/cssref/css_selectors.asp
http://www.w3schools.com/xml/xpath_intro.asp
THANK	YOU
sriramsb@thoughtworks.com
https://blogfromsriram.wordpress.com/

More Related Content

PPTX
Locators in selenium - BNT 09
PPTX
Css selector - BNT 11
PPTX
Selenium Locators
PPTX
How to use CSS Selector to identify Web Elements for selenium scripts
PDF
Completing Your Design with WordPress
PDF
Introduction to HTML, CSS, and Javascript
PPTX
CSC103 Web Technologies: HTML, CSS, JS
PDF
Knockout mvvm-m3-slides
Locators in selenium - BNT 09
Css selector - BNT 11
Selenium Locators
How to use CSS Selector to identify Web Elements for selenium scripts
Completing Your Design with WordPress
Introduction to HTML, CSS, and Javascript
CSC103 Web Technologies: HTML, CSS, JS
Knockout mvvm-m3-slides

What's hot (18)

PPTX
Css3 Presetation
PPTX
Efficient use of jQuery selector
PDF
Introduction to html & css
PDF
Intro to Javascript and jQuery
PDF
OmniAuth: From the Ground Up
PDF
Intro to jQuery
PPTX
Web Development Basics: HOW TO in HTML
PPTX
Introduction to jquery mobile with Phonegap
PDF
20180517 megurocss@1th
PDF
Class Intro / HTML Basics
PPT
Introduction to XML
PDF
2017年のteratailでやらかした話をしたい 20171213 _#9 _teratail_meetup
PPTX
Presentation about html5 css3
PDF
Fundamental CSS3
PDF
Html tutorials-infotech aus
PDF
Real Browser Check Scripting Guide - Rigor Monitoring
PDF
Learn css3
Css3 Presetation
Efficient use of jQuery selector
Introduction to html & css
Intro to Javascript and jQuery
OmniAuth: From the Ground Up
Intro to jQuery
Web Development Basics: HOW TO in HTML
Introduction to jquery mobile with Phonegap
20180517 megurocss@1th
Class Intro / HTML Basics
Introduction to XML
2017年のteratailでやらかした話をしたい 20171213 _#9 _teratail_meetup
Presentation about html5 css3
Fundamental CSS3
Html tutorials-infotech aus
Real Browser Check Scripting Guide - Rigor Monitoring
Learn css3
Ad

Similar to Techniques and tricks in using locators with selenium (20)

PDF
CSS Selector in Selenium WebDriver | Edureka
PDF
Html / CSS Presentation
PDF
TMW Code Club – Session 2 - CSS Basics
PDF
Test Automation Locator Strategy in selenium
PPT
Intro to CSS Selectors in Drupal
PPT
CSS, CSS Selectors, CSS Box Model
PPTX
Class andid
PDF
CSS Foundations, pt 1
PPT
dctagging: Encoding DC metadata using Structured Tags
PDF
Styling Components with JavaScript: MelbCSS Edition
PPT
Advanced Skinning with DotNetNuke 5
PPT
Advanced Skinning With DotNetNuke
PPT
Unit 2-CSS & Bootstrap.ppt
PPT
Rational HATS and CSS
PPT
An Introduction to CSS
PPTX
Gail Borden Library | HTML/CSS Program
PDF
GDI Seattle Intermediate HTML and CSS Class 1
PPTX
Hardcore CSS
PPTX
css.ppt
PDF
GDI Seattle - Intro to JavaScript Class 4
CSS Selector in Selenium WebDriver | Edureka
Html / CSS Presentation
TMW Code Club – Session 2 - CSS Basics
Test Automation Locator Strategy in selenium
Intro to CSS Selectors in Drupal
CSS, CSS Selectors, CSS Box Model
Class andid
CSS Foundations, pt 1
dctagging: Encoding DC metadata using Structured Tags
Styling Components with JavaScript: MelbCSS Edition
Advanced Skinning with DotNetNuke 5
Advanced Skinning With DotNetNuke
Unit 2-CSS & Bootstrap.ppt
Rational HATS and CSS
An Introduction to CSS
Gail Borden Library | HTML/CSS Program
GDI Seattle Intermediate HTML and CSS Class 1
Hardcore CSS
css.ppt
GDI Seattle - Intro to JavaScript Class 4
Ad

Recently uploaded (20)

PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
The various Industrial Revolutions .pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Tartificialntelligence_presentation.pptx
PDF
Five Habits of High-Impact Board Members
PDF
Architecture types and enterprise applications.pdf
PDF
STKI Israel Market Study 2025 version august
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
A contest of sentiment analysis: k-nearest neighbor versus neural network
Final SEM Unit 1 for mit wpu at pune .pptx
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
The various Industrial Revolutions .pptx
Zenith AI: Advanced Artificial Intelligence
Tartificialntelligence_presentation.pptx
Five Habits of High-Impact Board Members
Architecture types and enterprise applications.pdf
STKI Israel Market Study 2025 version august
Group 1 Presentation -Planning and Decision Making .pptx
sustainability-14-14877-v2.pddhzftheheeeee
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
1 - Historical Antecedents, Social Consideration.pdf
A novel scalable deep ensemble learning framework for big data classification...
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
NewMind AI Weekly Chronicles – August ’25 Week III
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
O2C Customer Invoices to Receipt V15A.pptx
Taming the Chaos: How to Turn Unstructured Data into Decisions

Techniques and tricks in using locators with selenium