XPath Axes

AxisName Description
ancestor Select all parent nodes(ancestor: parent,grandparent etc) of the current node.
ancestor-or-self Select all parent nodes(ancestor: parent,grandparent etc) of the current node and the node itself.
attribute Contains all attributes of the current node.
child Contains the children of the current node.
descendant Contains all children of the current node.
descendant-or-self Contains all children of the current node and the node itself.
following Select all nodes in the document that come after the current node.
following-sibling Contains all the following siblings of the current node.
Note: Siblings are the same level nodes as the current node.
parent Select the parent of the current node.
preceding Contains all nodes that come before the current node.
preceding-sibling Contains all siblings before the current node.
Note: Siblings are the same level nodes as the current node.

 

Axes usage is shown below:

'Without predicate

axisname::node_test

'with predicate

axisname::node_test[predicate]

 

In QTP:

Browser("name:=Working with XPath.*").WebElement("xpath:=target/axisname::node_text[predicate]").Click

Browser("name:=Working with XPath.*").WebElement("xpath:=(//tr[@class='row2'])[1]/descendant::td[1]").Click

posted @ 2013-11-21 09:36  dushuai  阅读(134)  评论(0编辑  收藏  举报