SlideShare a Scribd company logo
6
Most read
10
Most read
18
Most read
SELENIUM LOCATORS
PRELRIK.COM | PANKAJ DUBEYSELENIUM TUTORIAL | VIDEO: youtube.com/c/prelrik
What is SELENIUM LOCATOR
“Selenium locators are the identifiers to identify any web
element on webpage to perform action on it.”
Types of SELENIUM LOCATORS
1: ID
2: NAME
3: CLASS NAME
4: CSS Selector
5: Xpath
6: LINK TEXT
7: PARTIAL LINK TEXT
8: TAG NAME
MOST PREFERRED & USED
SELENIUM LOCATORS
---PREFERRED ---
● ID
● NAME
--- USED---
● xPATH
● CSS SELECTOR PATH
TOOL to generate xpath or css
selector
FIREBUG : A firefox plugin to inspect an
element on a web page
FirePath : A firefox plugin that works like a
plugin for FIREBUG
Inspect any element by right clicking on the element > and
then select INSPECT
Selenium locator ID
ID should be given the first priority if your are trying to locate
any web element as it gives the fastest result and hence your
script execution could be faster.
Syntax: driver.findElement(By.ID(“full-name”));
Selenium locator ID
Pros:
1: Fastest
2: Most preferred locator
Cons:
1: It works only when there is fixed ID attribute value
Selenium locator NAME
The name locator type will locate the first element with a
matching name attribute. If multiple elements have the same
value for a name attribute, then you can use filters to further
refine your location strategy.
Syntax: driver.findElement(By.Name(“full-name”));
Selenium locator CLASS
The class locator uses a specific class attribute to get to the
first element on a web page.
Syntax: driver.findElement(By.className(“class-name”));
Selenium locator LInkText
You can use the link text to locate an element using selenium.
Selenium locator tagName
You can locate an element by the tagName
Syntax: driver.findElements(By.tagName(“a”));
Selenium locator xPath..
● xPath stands for XML path
● XPath is the language used for locating nodes in an XML
document
● It’s most flexible to derive xPath to identify web elements
● You can use any node attribute to create xPath of an
element, but that attribute value should be unique in DOM
xPath Syntax: //*[@attributeName=’attributeValue’][@attribute2=’value’]
Types of xPath..
Absolute xPath
Syntax: /html/body/form/div/span/span
Relative xPath:
Syntax: //Input[@AttributeName=’value’]
xPath Methods..
● Contains()
Syntax: //*[contains(text(),'Email')]
● Starts-with()
Syntax: //*[starts-with(text(),'Pass')]
● text()
Syntax: //*[text()='Password']
xPath Advance..
● parent()
Syntax: //*[text()='Password']/parent::parentTagName[1]
● ancestor()
Syntax: //*[text()='Password']/ancestor::table
● descendant()
Syntax: .//*[@id='value']/descendant::h1
● preceding/following sibling()
Syntax: .//*[@class='_li']/div[1]/following-sibling::div
Selenium locator css Selector path (1/3)
● is the cascading stylesheet path
● Is a pattern to find an element in web page
syntax : [attribute-Name=’value’][attribute2=’value’]
How to create a css Selector path (2/3)
● You can use element ID by prefixing #
Syntax: #idValue
● You can use element Class Name by prefixing . (dot)
Syntax: .className
● You can use (>) to access the child elements
Syntax: .className>childNode
● You can use first-child, last-child or nth-child(n) methods to define the
position of child elements
Syntax: .className>childNodeName::nth-child(n)
How to create a css Selector path (3/3)
syntax : [attribute-Name=’value’][attribute2=’value’]
● Starts with = ^
Syntax: [attribute-Name^=’value’]
● Ends with = $
Syntax: [attribute-Name$=’value’]
● Contains = *
Syntax: [attribute-Name*=’value’]

More Related Content

What's hot (20)

PPTX
Locators in selenium - BNT 09
weekendtesting
 
PDF
Selenium IDE LOCATORS
Mindfire Solutions
 
PPTX
Test Automation and Selenium
Karapet Sarkisyan
 
PDF
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Edureka!
 
PDF
Page Object Model and Implementation in Selenium
Zoe Gilbert
 
PPTX
Selenium test automation
Srikanth Vuriti
 
PPT
Selenium Automation Framework
Mindfire Solutions
 
PPTX
Selenium WebDriver training
Vijay Krishnan Ramaswamy
 
PPTX
Selenium Locators
Satyam Pandey
 
PPTX
Introduction to Selenium Web Driver
Return on Intelligence
 
PPTX
Selenium WebDriver
Yuriy Bezgachnyuk
 
PPTX
An overview of selenium webdriver
Anuraj S.L
 
PDF
Page object pattern
Petro Konopelko
 
PPSX
Selenium WebDriver
Rajathi-QA
 
PPT
Selenium ppt
Naga Dinesh
 
PPTX
Hybrid automation framework
doai tran
 
PPTX
Python selenium
Ducat
 
PPTX
Selenium with java
Gousalya Ramachandran
 
PPTX
Selenium ppt
Aneesh Rangarajan
 
PDF
Automation Testing using Selenium
Naresh Chintalcheru
 
Locators in selenium - BNT 09
weekendtesting
 
Selenium IDE LOCATORS
Mindfire Solutions
 
Test Automation and Selenium
Karapet Sarkisyan
 
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Edureka!
 
Page Object Model and Implementation in Selenium
Zoe Gilbert
 
Selenium test automation
Srikanth Vuriti
 
Selenium Automation Framework
Mindfire Solutions
 
Selenium WebDriver training
Vijay Krishnan Ramaswamy
 
Selenium Locators
Satyam Pandey
 
Introduction to Selenium Web Driver
Return on Intelligence
 
Selenium WebDriver
Yuriy Bezgachnyuk
 
An overview of selenium webdriver
Anuraj S.L
 
Page object pattern
Petro Konopelko
 
Selenium WebDriver
Rajathi-QA
 
Selenium ppt
Naga Dinesh
 
Hybrid automation framework
doai tran
 
Python selenium
Ducat
 
Selenium with java
Gousalya Ramachandran
 
Selenium ppt
Aneesh Rangarajan
 
Automation Testing using Selenium
Naresh Chintalcheru
 

Similar to Selenium locators: ID, Name, xpath, CSS Selector advance methods (20)

PPTX
Agile_unit_2_newdddcdcdscdssvvdvdsvdsv.pptx
juzerlight53
 
PPTX
Agile_unit_2_newdddcdcdscdssvvdvdsvdsv.pptx
juzerlight53
 
PDF
How to use selenium locators effectively for web automation.pdf
pcloudy2
 
PDF
Selenium Overview
Abhijeet Vaikar
 
PPT
Web testing with selenium and by quontra solutions
QUONTRASOLUTIONS
 
PDF
findElement and findElements in Selenium_ Use Cases with Examples.pdf
Steve Wortham
 
PDF
CSS Selector in Selenium WebDriver | Edureka
Edureka!
 
PDF
Understanding CSS Selectors in Selenium.pdf
pCloudy
 
PPTX
Selenium training
Shivaraj R
 
PPTX
How Selenium Finds Elements
Maciej Wyrodek
 
PDF
Css locators
Prashanth Sams
 
PDF
Efficient Rails Test-Driven Development - Week 6
Marakana Inc.
 
PDF
2010 07-18.wa.rails tdd-6
Marakana Inc.
 
PPTX
Automatedtestingwithselenium shubham jain
Prashant Gurav
 
PDF
Using XPath in Selenium_ All you need to know.pdf
RobertMartin69776
 
PDF
Hands-on Guide to Object Identification
Dharmesh Vaya
 
PPTX
Session 02 - Object Identification - Part 1
SiddharthSelenium
 
PPTX
Selenium training for beginners
TIB Academy
 
PPTX
Automated_Testing_Selenium
Jagdish Kaushal
 
DOCX
ST LAB 15 (1).docx
AfrasAhmad3
 
Agile_unit_2_newdddcdcdscdssvvdvdsvdsv.pptx
juzerlight53
 
Agile_unit_2_newdddcdcdscdssvvdvdsvdsv.pptx
juzerlight53
 
How to use selenium locators effectively for web automation.pdf
pcloudy2
 
Selenium Overview
Abhijeet Vaikar
 
Web testing with selenium and by quontra solutions
QUONTRASOLUTIONS
 
findElement and findElements in Selenium_ Use Cases with Examples.pdf
Steve Wortham
 
CSS Selector in Selenium WebDriver | Edureka
Edureka!
 
Understanding CSS Selectors in Selenium.pdf
pCloudy
 
Selenium training
Shivaraj R
 
How Selenium Finds Elements
Maciej Wyrodek
 
Css locators
Prashanth Sams
 
Efficient Rails Test-Driven Development - Week 6
Marakana Inc.
 
2010 07-18.wa.rails tdd-6
Marakana Inc.
 
Automatedtestingwithselenium shubham jain
Prashant Gurav
 
Using XPath in Selenium_ All you need to know.pdf
RobertMartin69776
 
Hands-on Guide to Object Identification
Dharmesh Vaya
 
Session 02 - Object Identification - Part 1
SiddharthSelenium
 
Selenium training for beginners
TIB Academy
 
Automated_Testing_Selenium
Jagdish Kaushal
 
ST LAB 15 (1).docx
AfrasAhmad3
 
Ad

More from Pankaj Dubey (6)

PPTX
Software Testing interview - Q&A and tips
Pankaj Dubey
 
PPTX
Spoofing attack: Learn about Email spoofing, IP address spoofing and many other
Pankaj Dubey
 
PPTX
Social engineering hacking attack
Pankaj Dubey
 
PPTX
Hacking and Penetration Testing - a beginners guide
Pankaj Dubey
 
PPTX
Selenium introduction
Pankaj Dubey
 
PPTX
Software testing course - Manual
Pankaj Dubey
 
Software Testing interview - Q&A and tips
Pankaj Dubey
 
Spoofing attack: Learn about Email spoofing, IP address spoofing and many other
Pankaj Dubey
 
Social engineering hacking attack
Pankaj Dubey
 
Hacking and Penetration Testing - a beginners guide
Pankaj Dubey
 
Selenium introduction
Pankaj Dubey
 
Software testing course - Manual
Pankaj Dubey
 
Ad

Recently uploaded (20)

PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 

Selenium locators: ID, Name, xpath, CSS Selector advance methods

  • 1. SELENIUM LOCATORS PRELRIK.COM | PANKAJ DUBEYSELENIUM TUTORIAL | VIDEO: youtube.com/c/prelrik
  • 2. What is SELENIUM LOCATOR “Selenium locators are the identifiers to identify any web element on webpage to perform action on it.”
  • 3. Types of SELENIUM LOCATORS 1: ID 2: NAME 3: CLASS NAME 4: CSS Selector 5: Xpath 6: LINK TEXT 7: PARTIAL LINK TEXT 8: TAG NAME
  • 4. MOST PREFERRED & USED SELENIUM LOCATORS ---PREFERRED --- ● ID ● NAME --- USED--- ● xPATH ● CSS SELECTOR PATH
  • 5. TOOL to generate xpath or css selector FIREBUG : A firefox plugin to inspect an element on a web page FirePath : A firefox plugin that works like a plugin for FIREBUG Inspect any element by right clicking on the element > and then select INSPECT
  • 6. Selenium locator ID ID should be given the first priority if your are trying to locate any web element as it gives the fastest result and hence your script execution could be faster. Syntax: driver.findElement(By.ID(“full-name”));
  • 7. Selenium locator ID Pros: 1: Fastest 2: Most preferred locator Cons: 1: It works only when there is fixed ID attribute value
  • 8. Selenium locator NAME The name locator type will locate the first element with a matching name attribute. If multiple elements have the same value for a name attribute, then you can use filters to further refine your location strategy. Syntax: driver.findElement(By.Name(“full-name”));
  • 9. Selenium locator CLASS The class locator uses a specific class attribute to get to the first element on a web page. Syntax: driver.findElement(By.className(“class-name”));
  • 10. Selenium locator LInkText You can use the link text to locate an element using selenium.
  • 11. Selenium locator tagName You can locate an element by the tagName Syntax: driver.findElements(By.tagName(“a”));
  • 12. Selenium locator xPath.. ● xPath stands for XML path ● XPath is the language used for locating nodes in an XML document ● It’s most flexible to derive xPath to identify web elements ● You can use any node attribute to create xPath of an element, but that attribute value should be unique in DOM xPath Syntax: //*[@attributeName=’attributeValue’][@attribute2=’value’]
  • 13. Types of xPath.. Absolute xPath Syntax: /html/body/form/div/span/span Relative xPath: Syntax: //Input[@AttributeName=’value’]
  • 14. xPath Methods.. ● Contains() Syntax: //*[contains(text(),'Email')] ● Starts-with() Syntax: //*[starts-with(text(),'Pass')] ● text() Syntax: //*[text()='Password']
  • 15. xPath Advance.. ● parent() Syntax: //*[text()='Password']/parent::parentTagName[1] ● ancestor() Syntax: //*[text()='Password']/ancestor::table ● descendant() Syntax: .//*[@id='value']/descendant::h1 ● preceding/following sibling() Syntax: .//*[@class='_li']/div[1]/following-sibling::div
  • 16. Selenium locator css Selector path (1/3) ● is the cascading stylesheet path ● Is a pattern to find an element in web page syntax : [attribute-Name=’value’][attribute2=’value’]
  • 17. How to create a css Selector path (2/3) ● You can use element ID by prefixing # Syntax: #idValue ● You can use element Class Name by prefixing . (dot) Syntax: .className ● You can use (>) to access the child elements Syntax: .className>childNode ● You can use first-child, last-child or nth-child(n) methods to define the position of child elements Syntax: .className>childNodeName::nth-child(n)
  • 18. How to create a css Selector path (3/3) syntax : [attribute-Name=’value’][attribute2=’value’] ● Starts with = ^ Syntax: [attribute-Name^=’value’] ● Ends with = $ Syntax: [attribute-Name$=’value’] ● Contains = * Syntax: [attribute-Name*=’value’]