TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Selenium

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

  • Using relative XPath is simple and you don’t have to mention the long XPath.
  • Relative XPath would take more time in identifying the element as we specify the partial path, not the exact path.
  • If there are multiple elements for the same path, it will select the first element that is identified

XPath Axes

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

For example:

  • self: Selects the current node
  • ancestor: Selects all ancestors (parent, grandparent, etc.) of the current node
  • attribute: Selects all attributes of the current node
  • child: Selects all children of the current node

Related Posts

Selenium /

Add Microsoft Webdriver on Windows OS

Selenium /

Getting Started with Selenium Webdriver

Selenium /

LambdaTest – Testing Cloud SaaS Platform

Selenium /

Selenium 3.0 and Mozilla GeckoDriver

Selenium /

Run an Example Test on SauceLabs

‹ Learning Selenium WebDriver› Network Testing Tools

Recent Posts

  • Scaler Academy – An Online Learning Platform
  • Difference between PHP and JavaScript?
  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com