SlideShare a Scribd company logo
XPATH:
AN INTRODUCTION
● Web automation is the concept of letting software robots
perform pre-defined actions, tasks, and processes on a web
browser or web application.
What can you do with web automation?
Think of all the clicking and typing you do at your
desk every day involving websites and web-based applications.
All these actions can be automated with web automation.
Actions that can be automated include:
● Filling out forms and fields
● Scraping content from a web page
● Extracting and transferring data between applications
● Clicking buttons and element
What is Web Automation?
When talking about web automation, there is no way around Selenium, the
world’s most popular open-source framework for automating browsers.
Selenium is a free (open-source) automated testing framework used to validate
web applications across different browsers and platforms.
As we know, for automating any Web Applications, locating web elements is
one of the first steps. We need some unique attributes such as id, name,
className, etc. to identify the HTML elements. Sometimes, either due to
dynamic web elements or poor development practices, there are no unique
attributes associated with the Web Elements, and there comes the role
of XPath. As we know, when a web page loads in a browser, it generates
a DOM (Document Object Model) structure. XPath is the query language that
queries objects in the DOM.
XML Path or commonly known as XPath, is a query language
for XML documents.
XPath is used to find the location of any element on a
webpage using HTML DOM structure.
In automation, there may be times when elements cannot be
found with general locators like ID, name, class, etc. And this is
when XPath is used to locate those elements on the webpage.
WHAT IS XPATH
/bookstore/book[2]/author
SYNTAX OF XPATH
XPath=//tagname[@attribute='value']
• // : to select the current node.
• tag name: tag name of a specific node.
• @: to select the attribute.
• attribute: it is the attribute name of the node.
• value: it is the value of the node.
TYPES OF XPATH
There are two types of XPath:
• Absolute XPath
• Relative Xpath
Absolute Xpath
Absolute XPath is the direct way to find the element. But the disadvantage of the
absolute XPath is that if there are any changes made in the path of the element then
that XPath fails.
The key characteristic of XPath is that it begins with the single forward slash(/), which
means you can select the element from the root node.
EXAMPLE:
html/body/table/tr/td[1]/div/div/div/span/span/p/input
Relative Xpath
For Relative XPath, the path starts from the middle of the HTML DOM
structure. Unlike Absolute XPath, Relative XPath starts with the double
forward slash (//), which means it can search the element anywhere
on the webpage.
You can start from the middle of the HTML DOM structure with no
need to write a long XPath.
The element you are selecting should be stable and should be less
prone to changes.
XPATH FUNCTIONS
There may be times that while locating a particular web element using general
attributes, there are elements that have similar properties, like the same name or
the same class name. This is when the simple XPath strategies are not efficient and
the need for XPath Functions arises.
XPath Contains() function
XPath Text() function
XPath Starts-with() function
XPath Contains() function
The XPath Contains() is a function used to create an XPath expression. It is
used if part of the value of any attribute changes dynamically. The function
can navigate to the web element with the partial text present.
In the below XPath expression, the partial value 'Name' is used.
The complete value of 'id' is 'FirstName' but using only the partial value
'Name.’
XPath=//*[contains(@id,'Name’)
In the above expression, we have taken the 'id' as an attribute and 'Name'
as a partial value
The Starts-With Function
The Starts-With function finds the element whose attribute value changes on
refresh or any operation on the webpage. In this expression, match the starting
text of the attribute used to find the element whose attribute changes
dynamically. You can also find the element whose attribute value is static (does
not change).
For example, suppose the ID of a particular element changes dynamically like:
Id=" message12"
Id=" message345"
Id=" message8769"
And so on. But the initial text is the same.
XPath=//input[starts-with(@class,'form')]
Using Text()
In this expression, with the text function, we find the element
with the exact text match as shown below. In this case, we find
the element with the text “orders.“
XPath=//*[text()=‘orders']
IMPORTANCE
In simple terms, XPath is our savior when it comes to locating elements.
IDs, names are the best locating strategies to capture elements as they
are less prone to changes. In Selenium automation, if the elements are
not found by the general locators like id, class, name, etc. then XPath is
used to find an element on the web page.
THANK
YOU

More Related Content

Similar to xpaths.pptx

My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
Syed Irtaza Ali
 
J Query Introduction And JQuery Selectors
J Query Introduction And JQuery SelectorsJ Query Introduction And JQuery Selectors
J Query Introduction And JQuery Selectors
Anand Kumar Rajana
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Gunjan Kumar
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1
Salesforce Developers
 
SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...
SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...
SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...
Geoff Varosky
 
Web scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabsWeb scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabs
zekeLabs Technologies
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
Rohan Chandane
 
SessionTen_CaseStudies
SessionTen_CaseStudiesSessionTen_CaseStudies
SessionTen_CaseStudies
Hellen Gakuruh
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
AAFREEN SHAIKH
 
Ajax Part II
Ajax Part IIAjax Part II
Ajax Part II
Mukesh Tekwani
 
Struts2
Struts2Struts2
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
TechTalk: Taking the Mystery Out of Object ID Automation
TechTalk: Taking the Mystery Out of Object ID AutomationTechTalk: Taking the Mystery Out of Object ID Automation
TechTalk: Taking the Mystery Out of Object ID Automation
Lizzy Guido (she/her)
 
Java script basics
Java script basicsJava script basics
Java script basics
Thakur Amit Tomer
 
Bootcamp - Web Development Session 2
Bootcamp - Web Development Session 2Bootcamp - Web Development Session 2
Bootcamp - Web Development Session 2
GDSCUniversitasMatan
 
JS basics
JS basicsJS basics
JS basics
Mohd Saeed
 
BITM3730 10-4.pptx
BITM3730 10-4.pptxBITM3730 10-4.pptx
BITM3730 10-4.pptx
MattMarino13
 
BITM3730 10-3.pptx
BITM3730 10-3.pptxBITM3730 10-3.pptx
BITM3730 10-3.pptx
MattMarino13
 
Pascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax SecurityPascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax Security
amiable_indian
 
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
ujjwalmatoliya
 

Similar to xpaths.pptx (20)

My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
 
J Query Introduction And JQuery Selectors
J Query Introduction And JQuery SelectorsJ Query Introduction And JQuery Selectors
J Query Introduction And JQuery Selectors
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1
 
SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...
SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...
SharePoint Saturday Baltimore 7/25/09 - Introduction To Developing Custom Act...
 
Web scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabsWeb scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabs
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
 
SessionTen_CaseStudies
SessionTen_CaseStudiesSessionTen_CaseStudies
SessionTen_CaseStudies
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
 
Ajax Part II
Ajax Part IIAjax Part II
Ajax Part II
 
Struts2
Struts2Struts2
Struts2
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
TechTalk: Taking the Mystery Out of Object ID Automation
TechTalk: Taking the Mystery Out of Object ID AutomationTechTalk: Taking the Mystery Out of Object ID Automation
TechTalk: Taking the Mystery Out of Object ID Automation
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Bootcamp - Web Development Session 2
Bootcamp - Web Development Session 2Bootcamp - Web Development Session 2
Bootcamp - Web Development Session 2
 
JS basics
JS basicsJS basics
JS basics
 
BITM3730 10-4.pptx
BITM3730 10-4.pptxBITM3730 10-4.pptx
BITM3730 10-4.pptx
 
BITM3730 10-3.pptx
BITM3730 10-3.pptxBITM3730 10-3.pptx
BITM3730 10-3.pptx
 
Pascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax SecurityPascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax Security
 
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
 

Recently uploaded

Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
Kamal Acharya
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
Prakhyath Rai
 
AI-Based Home Security System : Home security
AI-Based Home Security System : Home securityAI-Based Home Security System : Home security
AI-Based Home Security System : Home security
AIRCC Publishing Corporation
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
b0754201
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
harshapolam10
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
vmspraneeth
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
PreethaV16
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
CVCSOfficial
 
2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt
abdatawakjira
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
MadhavJungKarki
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
sydezfe
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
Kamal Acharya
 

Recently uploaded (20)

Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
 
AI-Based Home Security System : Home security
AI-Based Home Security System : Home securityAI-Based Home Security System : Home security
AI-Based Home Security System : Home security
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
 
2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
 

xpaths.pptx

  • 2. ● Web automation is the concept of letting software robots perform pre-defined actions, tasks, and processes on a web browser or web application. What can you do with web automation? Think of all the clicking and typing you do at your desk every day involving websites and web-based applications. All these actions can be automated with web automation. Actions that can be automated include: ● Filling out forms and fields ● Scraping content from a web page ● Extracting and transferring data between applications ● Clicking buttons and element What is Web Automation?
  • 3. When talking about web automation, there is no way around Selenium, the world’s most popular open-source framework for automating browsers. Selenium is a free (open-source) automated testing framework used to validate web applications across different browsers and platforms. As we know, for automating any Web Applications, locating web elements is one of the first steps. We need some unique attributes such as id, name, className, etc. to identify the HTML elements. Sometimes, either due to dynamic web elements or poor development practices, there are no unique attributes associated with the Web Elements, and there comes the role of XPath. As we know, when a web page loads in a browser, it generates a DOM (Document Object Model) structure. XPath is the query language that queries objects in the DOM.
  • 4. XML Path or commonly known as XPath, is a query language for XML documents. XPath is used to find the location of any element on a webpage using HTML DOM structure. In automation, there may be times when elements cannot be found with general locators like ID, name, class, etc. And this is when XPath is used to locate those elements on the webpage. WHAT IS XPATH
  • 6.
  • 7. SYNTAX OF XPATH XPath=//tagname[@attribute='value'] • // : to select the current node. • tag name: tag name of a specific node. • @: to select the attribute. • attribute: it is the attribute name of the node. • value: it is the value of the node.
  • 8. TYPES OF XPATH There are two types of XPath: • Absolute XPath • Relative Xpath Absolute Xpath Absolute XPath is the direct way to find the element. But the disadvantage of the absolute XPath is that if there are any changes made in the path of the element then that XPath fails. The key characteristic of XPath is that it begins with the single forward slash(/), which means you can select the element from the root node. EXAMPLE: html/body/table/tr/td[1]/div/div/div/span/span/p/input
  • 9. Relative Xpath For Relative XPath, the path starts from the middle of the HTML DOM structure. Unlike Absolute XPath, Relative XPath starts with the double forward slash (//), which means it can search the element anywhere on the webpage. You can start from the middle of the HTML DOM structure with no need to write a long XPath. The element you are selecting should be stable and should be less prone to changes.
  • 10.
  • 11. XPATH FUNCTIONS There may be times that while locating a particular web element using general attributes, there are elements that have similar properties, like the same name or the same class name. This is when the simple XPath strategies are not efficient and the need for XPath Functions arises. XPath Contains() function XPath Text() function XPath Starts-with() function
  • 12. XPath Contains() function The XPath Contains() is a function used to create an XPath expression. It is used if part of the value of any attribute changes dynamically. The function can navigate to the web element with the partial text present. In the below XPath expression, the partial value 'Name' is used. The complete value of 'id' is 'FirstName' but using only the partial value 'Name.’ XPath=//*[contains(@id,'Name’) In the above expression, we have taken the 'id' as an attribute and 'Name' as a partial value
  • 13. The Starts-With Function The Starts-With function finds the element whose attribute value changes on refresh or any operation on the webpage. In this expression, match the starting text of the attribute used to find the element whose attribute changes dynamically. You can also find the element whose attribute value is static (does not change). For example, suppose the ID of a particular element changes dynamically like: Id=" message12" Id=" message345" Id=" message8769" And so on. But the initial text is the same. XPath=//input[starts-with(@class,'form')]
  • 14. Using Text() In this expression, with the text function, we find the element with the exact text match as shown below. In this case, we find the element with the text “orders.“ XPath=//*[text()=‘orders']
  • 15. IMPORTANCE In simple terms, XPath is our savior when it comes to locating elements. IDs, names are the best locating strategies to capture elements as they are less prone to changes. In Selenium automation, if the elements are not found by the general locators like id, class, name, etc. then XPath is used to find an element on the web page.