Difference between //, .//, and ..// in XPath?
Can anyone please help with the difference between the below XPaths and help me understand which of these to use when. I have found all three of them to work but not sure when to use them.
-
Get Element Text ${output} //priority
-
Get Element Text ${output} .//vrrp-group/name
-
Get Element Text ${output} ..//track/priority-hold-time
Solution 1:
Difference between //, .//, and ..// in XPath in general
//
selects among descendant or self nodes (along the descendant-or-self
axis). It is short for /descendant-or-self::node()/
.
-
//
starts from the root node, thus covering the entire document. -
.//
starts from the context node. -
..//
starts from the parent of the context node.
In your particular case
-
//priority
selects allpriority
elements in the document. -
.//vrrp-group/name
selects, beneath the context node, allname
elements with avrrp-group
parent. -
..//track/priority-hold-time
selects, beneath the parent of the context node, allpriority-hold-time
elements with atrack
parent.
Robotframework note:
In the context of the Get Element Text
Robotframework XML library command, the XPath must be relative to the source node (${output}
in your case). Absolute XPaths such as //priority
are not allowed there.
See also
- Difference between "//" and "/" in XPath?
- What is the difference between .// and //* in XPath?
- What is meaning of .// in XPath?