1

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.

  1. Get Element Text ${output} //priority

  2. Get Element Text ${output} .//vrrp-group/name

  3. Get Element Text ${output} ..//track/priority-hold-time

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685

1 Answers1

4

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()/.

  1. // starts from the root node, thus covering the entire document.
  2. .// starts from the context node.
  3. ..// starts from the parent of the context node.

In your particular case

  1. //priority selects all priority elements in the document.
  2. .//vrrp-group/name selects, beneath the context node, all name elements with a vrrp-group parent.
  3. ..//track/priority-hold-time selects, beneath the parent of the context node, all priority-hold-time elements with a track 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

kjhughes
  • 106,133
  • 27
  • 181
  • 240