Absolute and Relative XPath
Let’s find out about the difference between absolute and relative XPath in this lesson.
We'll cover the following...
What is an absolute and relative XPath?
In an absolute XPath, you traverse from the top of the hierarchy, say html
or body
node, until the target node in the DOM.
In a relative XPath, as the name suggests, we can start locating the element from anywhere in the hierarchy tree, including the same exact node.
Let’s look at the example below, where the same node is identified using one absolute and multiple relative XPaths:
-
Absolute XPath
/html/body/div/ul/li[@id='xyz']
-
Relative XPath