Site icon TestingDocs.com

XPath Tutorial for Automation

Introduction

XPath allows the selection of elements, attributes, etc. of XML (The Extensible Mark-up Language) documents, web pages for processing in Web automation scripts. As an analogy, XPath is something similar to SQL used on database schema to select or retrieve data from the database.

XML

XML is a standard syntax for the markup of data and documents.XML documents contain one or more elements. The text contained between the start tag and the end tag is the element’s content.

An XML Element may have attributes, which will provide information about the element type or its content.

Absolute XPath vs Relative XPath

The absolute XPath starts with the root node or a forward slash (/).
The advantage of using absolute is, it identifies the element very fast.
The disadvantage of using absolute path is if some other tag added in between, then this path would be broken.

 

For Example:  /html/head/body

A relative XPath is one where the path starts from the node of your choice – it doesn’t need to start from the root node. It starts with Double forward slash(//)

For Example: //table/tbody/tr

XPath Axes

XPath axis tells the XPath processor which direction to head in as it navigates around the hierarchical tree of nodes.

For example:

Exit mobile version