A Relative XPath is the path which starts from
the node of our choice and is prefixed with a ' // '. It doesn't need to
start from the root node.
For example:
//span[@class = 'Email']
Pros
- It starts from the node of our choice
- It is readable and shorter than Absolute XPath
- It works even after structural change
Cons
- It takes more time to identify element as we specify the partial path
- If there are multiple elements for the same path, it will select the first element that is identified
Let's take a look at a Relative XPath below:
//li[@id = 'ogbkddg:4']
Here,
//li[@id = 'ogbkddg:4'] is a Relative XPath and as we can see it did not start from the root node
and started from the node of our choice. It is also short and very easy
to read. Even if there is any kind of structural change, it will work
just fine.
No comments:
Post a Comment