Xpath In Selenium


Xpath in Selenium


XPath (XML Path Language) is a query language for selecting elements from an XML/HTML document.

It helps you find an element from the whole document precisely and quickly.

Web pages are generally written in a language called HTML. If you load a web page on a browser (Chrome, Firefox, etc), you can easily access the corresponding HTML doc by hitting the F12 key.

Before going to create a Xpath, we need to understand few basic terms.

What is meant by nodes in Xpath ?


  • In XPath, there are many kinds of nodes for example element node, attribute node, text node, namespace, Text, processing-instruction, comment, and document nodes .
  • XML documents are treated as trees of nodes. The topmost element of the tree is called the root element.
  • Few example of nodes except root node.
    • Element node: represents the HTML element, i.e an HTML tag.
    • Attribute node: it represents an attribute in an element node, e.g. “href” attribute in <a href=”http://www.selenium.com”>example</a>
    • Comment node: represents comments in the HTML document which is denoted by (<!– … –>)
    • Text node: represents the text enclosed in an element node (example in <p>example</p>)


What is meant by Atomic values in Xpath ?


  • Atomic values are nodes with no children or parent.


What is meant by Items in Xpath ?


  • Items are atomic values or nodes.


Apart form this you should also understand the relationship between nodes

Xpath Axis OR Relationship of Nodes (with Examples)

To be added... by 03 June 2020

Post a Comment