SlideShare a Scribd company logo
1 of 25
How to find
Xpath of an
element??
Mithilesh Singh
Locators & xpath
Locators
 identification of the
correct GUI element on a web page is
pre-requisite for creating any
successful automation script. It is
where locators come into the
picture. Locators are one of the
essential components of Selenium
infrastructure, which help Selenium
scripts in uniquely identifying
the WebElements(such as text box,
button, etc.)
 Types of locators:
ID,
Class,
Tag, Link,
Partial Link Text,
CSS, Name,
XPath.
What is DOM?
 The Document Object Model
(DOM) is a programming API
for HTML and XML
documents. It defines the
logical structure of
documents and the way a
document is accessed and
manipulated. ... Nevertheless,
XML presents this data as
documents, and
the DOM may be used to
manage this data.
XPath in
Selenium:
 XPath is a technique in Selenium to navigate
through the HTML structure of a page. XPath enables
testers to navigate through the XML structure of any
document, and this can be used on both HTML and
XML documents.
 1. While Selenium has wrappers for most popular
programming languages, the selector string remains
the same for all of them.
 2. While other locators in Selenium which search for
elements using tags or CSS class names are simpler
to use, they may not be sufficient to select all DOM
elements of an HTML document.
 XPath is defined as XML path. It is a syntax or
language for finding any element on the web page
using the XML path expression.
Syntax of Xpath
 XPath =
//tag_name[@Attribute_name =
“Value of attribute”]
 // --> Select current node.
 tag_name --> Tagname of the
particular node.
 @ --> Select attribute.
 Attribute_name --> Attribute name
of the node.
 Value of attribute --> Value of the
attribute.
Types of XPath
Absolute Xpath
 Absolute XPath is the direct way of
finding the element. Moreover, it
starts from the first/root node of
the XML/HTML document and
goes all the way to the required
node following one node at a
time.
Example:
/html/body/div/header/a/img
Relative Xpath
 Relative XPath starts from any node inside
the HTML DOM; it need not start from
the root node. It beings with a double
forward slash.
Example:
//img[@src= "/images/Testerszone.jpg"]
Relative Xpath Syntax for Pre - defined locators:
 Using text() : //*[text()='testers zone']
 Using name() : //input[@name='Mithilesh']
 Using id() : //input[@id='user-message‘]
 Using class() : //input[@class='user-message']
 LinkText() : //a[@href='http://testerszone.com/']
Note: We can use * in place of input, it will also work fine. Input is specific
tag name but * is generic(point out all the available tags in the DOM) we
can use for any tag name.
Key Points:
We can directly use the pre defined
locators in findElement method instead
of xpath.
driver.findElement(By.id("Testers Zone"));
Note:
We can use other locators like name,
className etc in same way.
You will get to know all available locators using
driver.findElement(By. );
Use of Contains() in Xpath
• Contains() method always use in xpath to get the element using partial text.
• Whenever we have long text or dynamic text we go with contains().
Using text() : //*[contains(text(),'testers ')]
Using name() : //input[contains(@name,'Mith')]
Using id() : //input[contains(@id,'user-message‘)]
Using class() : //input[contains(@class,'user-message')]
Partial-LinkText() : //a[contains(@href,'testerszone.com']
Use of
Starts-with()
 starts-with() method is used when we know
about the initial partial attribute value or
initial partial text associated with the web
element.
Syntax:
//a[starts-with(@id,'link-testers_')]
Note: inside the ' ' you have to mention the
partial text value, make sure you are getting
unique matching element with your xpath.
Simillar way we have ends_with() also. We use
end partial part of text.
Use of
OR & AND

Xpath=//input[@type='submit' and @name='btnLogin']
XPath axes
method
Sometimes we don't get element very easily so we need to use axes method in xpath, we use this to find complex and dynamic
element also.
1. Following:
This will give you the count of total elements in a document of the current node and we can access them using index.
Syntax:
Xpath=//*[@type='text']//following::input
2.Ancestor The ancestor axis selects all ancestors element (parent, grandparent, great-
grandparents, etc.) of the current node.
Syntax:
Xpath=//*[@type='text']//ancestor::div
3. Child
Select all the child elements of the current node.
Xpath= //*[@class='ng-lns-c59-10']//child::tr
4. Preceding
Select all nodes that come before the current
node
Xpath= //*[@type='password']//preceding::input
5. Following-sibling:
The following-sibling selects all sibling nodes after the current node at the same level. i.e. It will find the element
after the current node.
Xpath=//div[@id='nlplmgContainer']//following-
sibling::input
6. Parent
It select the parent of the current node.
Xpath= //*[@type='password']//parent::div
7. Descendant It select below child and grand child node of the curent node.
Note: There is small difference between descendant and following, following gives all the
mathing node in the document and descendant gives elements of current node only.
Introduction- CSS Selector
 CSS stands for Cascading spreadsheets, it is a stylesheet language use to describe
the presentation of the document written in mark up language like HTML
 We use CSS selector as a locator in the selenium
 It is very fast as compare to other locators because it uses certain symbol
There are three important special characters in css selectors:
1. '^' symbol, represents the starting text in a string.
2. '$' symbol represents the ending text in a string.
3. '*' symbol represents contains text in a string.
Partial Value is nothing but partial linked text, In CSS
we use * for this.
Example
 css = input[id$='mail']
 css = input[id*='mai']
 css = input[id^='ema']
 using child selectors--> css = form>label>input[id=PersistentCookie]
 using multiple node --> css = input[name=email][type=text]
Key Points:
Xpath :
 XPath stands for XML Path
 XPath is used to find the element in the HTML
DOM
 The success rate of finding an element using
Xpath is too high
 XPath is used where element has no other way
of locating
 Locate elements in forward and backward
direction.
 Can locate element by text
 Starts with / or //
 More flexible
CSS Selector :
 CSS stands for cascading style sheet
 CSS Selector is used to find the element in the
HTML DOM using style sheet language.
 The success rate of finding an element using
CSS Selector is less compare to Xpath.
 do not support all CSS features.
 Faster in all browsers
 Can not locate by element by text
 Locate elements only in forward direction
 Some CSS selectors will not work all browsers
By Mithilesh Singh

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
 
Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and SeleniumKarapet Sarkisyan
 
Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Frameworkvaluebound
 
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesVijay Rangaiah
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriverRajathi-QA
 
Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Edureka!
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaEdureka!
 
Test automation using selenium
Test automation using seleniumTest automation using selenium
Test automation using seleniumshreyas JC
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium Zoe Gilbert
 
Automated Web Testing Using Selenium
Automated Web Testing Using SeleniumAutomated Web Testing Using Selenium
Automated Web Testing Using SeleniumWeifeng Zhang
 
What is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | EdurekaWhat is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | EdurekaEdureka!
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.pptAna Sarbescu
 

What's hot (20)

An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
 
Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Framework
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering Colleges
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
Selenium
SeleniumSelenium
Selenium
 
Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
 
Test automation using selenium
Test automation using seleniumTest automation using selenium
Test automation using selenium
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium
 
Page object pattern
Page object patternPage object pattern
Page object pattern
 
Automated Web Testing Using Selenium
Automated Web Testing Using SeleniumAutomated Web Testing Using Selenium
Automated Web Testing Using Selenium
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
What is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | EdurekaWhat is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | Edureka
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.ppt
 

Similar to Selenium-Locators

Xsd restrictions, xsl elements, dhtml
Xsd restrictions, xsl elements, dhtmlXsd restrictions, xsl elements, dhtml
Xsd restrictions, xsl elements, dhtmlAMIT VIRAMGAMI
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scalaKnoldus Inc.
 
Using XPath in Selenium_ All you need to know.pdf
Using XPath in Selenium_ All you need to know.pdfUsing XPath in Selenium_ All you need to know.pdf
Using XPath in Selenium_ All you need to know.pdfRobertMartin69776
 
Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12RohanMistry15
 
1. Advanced Web Designing (12th IT) (1).pdf
1. Advanced Web Designing (12th IT) (1).pdf1. Advanced Web Designing (12th IT) (1).pdf
1. Advanced Web Designing (12th IT) (1).pdfAAFREEN SHAIKH
 
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptxGlobal Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptxujjwalmatoliya
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)mussawir20
 
Empowerment Technologies Lecture 10 (Philippines SHS)
Empowerment Technologies Lecture 10 (Philippines SHS)Empowerment Technologies Lecture 10 (Philippines SHS)
Empowerment Technologies Lecture 10 (Philippines SHS)John Bosco Javellana, MAEd.
 
Understanding CSS Selectors in Selenium.pdf
Understanding CSS Selectors in Selenium.pdfUnderstanding CSS Selectors in Selenium.pdf
Understanding CSS Selectors in Selenium.pdfpCloudy
 
DOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om SivanesianDOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om SivanesianMatthew McCullough
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2Neeraj Mathur
 
Introduction to whats new in css3
Introduction to whats new in css3Introduction to whats new in css3
Introduction to whats new in css3Usman Mehmood
 

Similar to Selenium-Locators (20)

xpaths.pptx
xpaths.pptxxpaths.pptx
xpaths.pptx
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Xsd restrictions, xsl elements, dhtml
Xsd restrictions, xsl elements, dhtmlXsd restrictions, xsl elements, dhtml
Xsd restrictions, xsl elements, dhtml
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 
XML
XMLXML
XML
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
Using XPath in Selenium_ All you need to know.pdf
Using XPath in Selenium_ All you need to know.pdfUsing XPath in Selenium_ All you need to know.pdf
Using XPath in Selenium_ All you need to know.pdf
 
Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12
 
1. Advanced Web Designing (12th IT) (1).pdf
1. Advanced Web Designing (12th IT) (1).pdf1. Advanced Web Designing (12th IT) (1).pdf
1. Advanced Web Designing (12th IT) (1).pdf
 
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptxGlobal Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
 
Xml session
Xml sessionXml session
Xml session
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)
 
Empowerment Technologies Lecture 10 (Philippines SHS)
Empowerment Technologies Lecture 10 (Philippines SHS)Empowerment Technologies Lecture 10 (Philippines SHS)
Empowerment Technologies Lecture 10 (Philippines SHS)
 
Xml and Co.
Xml and Co.Xml and Co.
Xml and Co.
 
Understanding CSS Selectors in Selenium.pdf
Understanding CSS Selectors in Selenium.pdfUnderstanding CSS Selectors in Selenium.pdf
Understanding CSS Selectors in Selenium.pdf
 
DOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om SivanesianDOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om Sivanesian
 
XML Schema.pptx
XML Schema.pptxXML Schema.pptx
XML Schema.pptx
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2
 
Introduction to whats new in css3
Introduction to whats new in css3Introduction to whats new in css3
Introduction to whats new in css3
 

More from Mithilesh Singh (20)

Cucumber Basics.pdf
Cucumber Basics.pdfCucumber Basics.pdf
Cucumber Basics.pdf
 
Data Migration.pdf
Data Migration.pdfData Migration.pdf
Data Migration.pdf
 
SDLC Models.pdf
SDLC Models.pdfSDLC Models.pdf
SDLC Models.pdf
 
Test_Case_Design_Techniques
Test_Case_Design_TechniquesTest_Case_Design_Techniques
Test_Case_Design_Techniques
 
Performance Testing
Performance TestingPerformance Testing
Performance Testing
 
Software_requirement_collection
Software_requirement_collectionSoftware_requirement_collection
Software_requirement_collection
 
Stub_&_Drive
Stub_&_DriveStub_&_Drive
Stub_&_Drive
 
Functional_Testing_Part-1
Functional_Testing_Part-1Functional_Testing_Part-1
Functional_Testing_Part-1
 
TestersMindSet 2022
TestersMindSet 2022TestersMindSet 2022
TestersMindSet 2022
 
API_Testing_with_Postman
API_Testing_with_PostmanAPI_Testing_with_Postman
API_Testing_with_Postman
 
Agile_basics
Agile_basicsAgile_basics
Agile_basics
 
Selenium_Grid
Selenium_GridSelenium_Grid
Selenium_Grid
 
Appium_set_up
Appium_set_upAppium_set_up
Appium_set_up
 
Appium- part 1
Appium- part 1Appium- part 1
Appium- part 1
 
Alpha & Beta Testing
Alpha & Beta TestingAlpha & Beta Testing
Alpha & Beta Testing
 
Severity and Priority
Severity and PrioritySeverity and Priority
Severity and Priority
 
GIT_Overview.
GIT_Overview.GIT_Overview.
GIT_Overview.
 
Browser_Stack_Intro
Browser_Stack_IntroBrowser_Stack_Intro
Browser_Stack_Intro
 
UI_UX_testing tips
UI_UX_testing tipsUI_UX_testing tips
UI_UX_testing tips
 
Emulator vs Simulator
Emulator vs SimulatorEmulator vs Simulator
Emulator vs Simulator
 

Recently uploaded

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
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
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
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
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

Selenium-Locators

  • 1. How to find Xpath of an element?? Mithilesh Singh Locators & xpath
  • 2. Locators  identification of the correct GUI element on a web page is pre-requisite for creating any successful automation script. It is where locators come into the picture. Locators are one of the essential components of Selenium infrastructure, which help Selenium scripts in uniquely identifying the WebElements(such as text box, button, etc.)  Types of locators: ID, Class, Tag, Link, Partial Link Text, CSS, Name, XPath.
  • 3. What is DOM?  The Document Object Model (DOM) is a programming API for HTML and XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated. ... Nevertheless, XML presents this data as documents, and the DOM may be used to manage this data.
  • 4. XPath in Selenium:  XPath is a technique in Selenium to navigate through the HTML structure of a page. XPath enables testers to navigate through the XML structure of any document, and this can be used on both HTML and XML documents.  1. While Selenium has wrappers for most popular programming languages, the selector string remains the same for all of them.  2. While other locators in Selenium which search for elements using tags or CSS class names are simpler to use, they may not be sufficient to select all DOM elements of an HTML document.  XPath is defined as XML path. It is a syntax or language for finding any element on the web page using the XML path expression.
  • 5. Syntax of Xpath  XPath = //tag_name[@Attribute_name = “Value of attribute”]  // --> Select current node.  tag_name --> Tagname of the particular node.  @ --> Select attribute.  Attribute_name --> Attribute name of the node.  Value of attribute --> Value of the attribute.
  • 6. Types of XPath Absolute Xpath  Absolute XPath is the direct way of finding the element. Moreover, it starts from the first/root node of the XML/HTML document and goes all the way to the required node following one node at a time. Example: /html/body/div/header/a/img Relative Xpath  Relative XPath starts from any node inside the HTML DOM; it need not start from the root node. It beings with a double forward slash. Example: //img[@src= "/images/Testerszone.jpg"]
  • 7. Relative Xpath Syntax for Pre - defined locators:  Using text() : //*[text()='testers zone']  Using name() : //input[@name='Mithilesh']  Using id() : //input[@id='user-message‘]  Using class() : //input[@class='user-message']  LinkText() : //a[@href='http://testerszone.com/'] Note: We can use * in place of input, it will also work fine. Input is specific tag name but * is generic(point out all the available tags in the DOM) we can use for any tag name.
  • 8. Key Points: We can directly use the pre defined locators in findElement method instead of xpath. driver.findElement(By.id("Testers Zone")); Note: We can use other locators like name, className etc in same way. You will get to know all available locators using driver.findElement(By. );
  • 9. Use of Contains() in Xpath • Contains() method always use in xpath to get the element using partial text. • Whenever we have long text or dynamic text we go with contains(). Using text() : //*[contains(text(),'testers ')] Using name() : //input[contains(@name,'Mith')] Using id() : //input[contains(@id,'user-message‘)] Using class() : //input[contains(@class,'user-message')] Partial-LinkText() : //a[contains(@href,'testerszone.com']
  • 10. Use of Starts-with()  starts-with() method is used when we know about the initial partial attribute value or initial partial text associated with the web element. Syntax: //a[starts-with(@id,'link-testers_')] Note: inside the ' ' you have to mention the partial text value, make sure you are getting unique matching element with your xpath. Simillar way we have ends_with() also. We use end partial part of text.
  • 11. Use of OR & AND  Xpath=//input[@type='submit' and @name='btnLogin']
  • 12. XPath axes method Sometimes we don't get element very easily so we need to use axes method in xpath, we use this to find complex and dynamic element also. 1. Following: This will give you the count of total elements in a document of the current node and we can access them using index. Syntax: Xpath=//*[@type='text']//following::input
  • 13. 2.Ancestor The ancestor axis selects all ancestors element (parent, grandparent, great- grandparents, etc.) of the current node. Syntax: Xpath=//*[@type='text']//ancestor::div
  • 14. 3. Child Select all the child elements of the current node. Xpath= //*[@class='ng-lns-c59-10']//child::tr
  • 15. 4. Preceding Select all nodes that come before the current node Xpath= //*[@type='password']//preceding::input
  • 16. 5. Following-sibling: The following-sibling selects all sibling nodes after the current node at the same level. i.e. It will find the element after the current node. Xpath=//div[@id='nlplmgContainer']//following- sibling::input
  • 17. 6. Parent It select the parent of the current node. Xpath= //*[@type='password']//parent::div
  • 18. 7. Descendant It select below child and grand child node of the curent node. Note: There is small difference between descendant and following, following gives all the mathing node in the document and descendant gives elements of current node only.
  • 19. Introduction- CSS Selector  CSS stands for Cascading spreadsheets, it is a stylesheet language use to describe the presentation of the document written in mark up language like HTML  We use CSS selector as a locator in the selenium  It is very fast as compare to other locators because it uses certain symbol
  • 20.
  • 21. There are three important special characters in css selectors: 1. '^' symbol, represents the starting text in a string. 2. '$' symbol represents the ending text in a string. 3. '*' symbol represents contains text in a string.
  • 22. Partial Value is nothing but partial linked text, In CSS we use * for this.
  • 23. Example  css = input[id$='mail']  css = input[id*='mai']  css = input[id^='ema']  using child selectors--> css = form>label>input[id=PersistentCookie]  using multiple node --> css = input[name=email][type=text]
  • 24. Key Points: Xpath :  XPath stands for XML Path  XPath is used to find the element in the HTML DOM  The success rate of finding an element using Xpath is too high  XPath is used where element has no other way of locating  Locate elements in forward and backward direction.  Can locate element by text  Starts with / or //  More flexible CSS Selector :  CSS stands for cascading style sheet  CSS Selector is used to find the element in the HTML DOM using style sheet language.  The success rate of finding an element using CSS Selector is less compare to Xpath.  do not support all CSS features.  Faster in all browsers  Can not locate by element by text  Locate elements only in forward direction  Some CSS selectors will not work all browsers