简体   繁体   English

XPath 中 //、.// 和 ..// 之间的区别?

[英]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.任何人都可以帮助解决以下 XPath 之间的区别,并帮助我了解何时使用其中的哪些。 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

In general一般来说

// selects among descendant or self nodes (along the descendant-or-self axis ). //在后代节点或自身节点之间进行选择(沿descendant-or-self节点descendant-or-self)。 It is short for /descendant-or-self::node()/ .它是/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. //priority选择文档中的所有priority元素。
  2. .//vrrp-group/name selects, beneath the context node, all name elements with a vrrp-group parent. .//vrrp-group/name在上下文节点下选择所有具有vrrp-group父级的name元素。
  3. ..//track/priority-hold-time selects, beneath the parent of the context node, all priority-hold-time elements with a track parent. ..//track/priority-hold-time在上下文节点的父节点下选择所有具有track父节点的priority-hold-time元素。

Robotframework note: Robotframework注意事项:

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).Get Element Text Robotframework XML 库命令的上下文中,XPath 必须相对于节点(在您的情况下${output} )。 Absolute XPaths such as //priority are not allowed there.那里不允许使用绝对 XPath,例如//priority

See also也可以看看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM