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

Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and SeleniumKarapet Sarkisyan
 
Introduction to Selenium Automation
Introduction to Selenium AutomationIntroduction to Selenium Automation
Introduction to Selenium AutomationMindfire Solutions
 
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
 
Waits in Selenium | Selenium Wait Commands | Edureka
Waits in Selenium | Selenium Wait Commands | EdurekaWaits in Selenium | Selenium Wait Commands | Edureka
Waits in Selenium | Selenium Wait Commands | EdurekaEdureka!
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with seleniumTzirla Rozental
 
Keyword-driven Test Automation Framework
Keyword-driven Test Automation FrameworkKeyword-driven Test Automation Framework
Keyword-driven Test Automation FrameworkMikhail Subach
 
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...Edureka!
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaEdureka!
 
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!
 
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 Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersAjit Jadhav
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriverAnuraj S.L
 
Katalon Studio - GUI Overview
Katalon Studio - GUI OverviewKatalon Studio - GUI Overview
Katalon Studio - GUI OverviewKatalon Studio
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using SeleniumNaresh Chintalcheru
 

What's hot (20)

Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and Selenium
 
Selenium Concepts
Selenium ConceptsSelenium Concepts
Selenium Concepts
 
Introduction to Selenium Automation
Introduction to Selenium AutomationIntroduction to Selenium Automation
Introduction to Selenium Automation
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
 
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
 
Waits in Selenium | Selenium Wait Commands | Edureka
Waits in Selenium | Selenium Wait Commands | EdurekaWaits in Selenium | Selenium Wait Commands | Edureka
Waits in Selenium | Selenium Wait Commands | Edureka
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Keyword-driven Test Automation Framework
Keyword-driven Test Automation FrameworkKeyword-driven Test Automation Framework
Keyword-driven Test Automation Framework
 
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
 
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
 
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
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
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 Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
Katalon Studio - GUI Overview
Katalon Studio - GUI OverviewKatalon Studio - GUI Overview
Katalon Studio - GUI Overview
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 

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

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
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
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
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
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
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
 
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.
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 

Recently uploaded (20)

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
 
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...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
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
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
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
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
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)
 
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 ...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 

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