Most examples start with /form (top-level applications). In real projects, you typically add an attribute to target the right app instance (for example, [@controlname='RxMainFrame'] in the Ranorex Studio Demo Application).
Axes
An axis represents a relationship to the context (current) node and is used to locate nodes relative to that node on the element tree. The context node is always the node before the axis.
All axes require further specification; they cannot stand alone. You can either specify a role (with or without a predicate) or use the any /* or any optional /? wildcards.
This does not apply to the abbreviations // (descendant-or-self) and .. (parent). This is explained under the respective axis.
| Axis (syntax) | Returns | Example |
child:: |
Returns all children of the context node. | /form/child::button |
descendant:: |
Returns all descendants of the context node. |
Returns all descendants of |
descendant-or-self:: or //
|
Returns the context node and all its descendants. For the abbreviated syntax //, further specification is optional. |
Only returns the descendants of |
parent:: or ..
|
Returns the parent of the context node. In its abbreviated syntax, it must stand alone and does not accept further specification. |
Example 1: Returns the parent of the specified button element if it has the role |
ancestor:: |
Returns all ancestors of the context node. |
Finds all buttons that are descendants of |
ancestor-or-self:: |
Returns the context node and all its ancestors. |
Finds all buttons that are descendants of |
preceding-sibling:: |
Returns all siblings before the context node. |
Returns all UI elements that have the role |
following-sibling:: |
Returns all siblings after the context node. |
Returns all UI elements that have the role |
Returns all UI elements that have the role buttonare siblings of the specified button and come after it.
Attributes
| Syntax | Meaning |
/form |
Top-level applications usually have the role form. This syntax therefore identifies top-level applications. |
/form[@title='Calculator'] |
Identifies top-level applications that have the title Calculator. |
/form[@title='Calculator' and @instance='2'] |
Identifies the top-level application that has the title Calculator AND the instance attribute 2. |
/form[@title='Calculator' or @class='SciCalc'] |
Identifies top-level applications that have the title Calculator OR the class SciCalc. |
/button |
Identifies UI elements that have the role button. |
/button[2] |
Identifies the second button (refers to the position in the element tree). |
/button[-2] |
Identifies the second-to-last button (refers to the position in the element tree). |
/button[@text='Exit'] |
Identifies buttons with the text Exit. |
/button[@text!='Exit'] |
Identifies buttons whose text attribute is not equal to Exit. |
/button[@text>'Warning'] |
Identifies buttons whose text begins with Warning. |
/button[@text<'Warning'] |
Identifies buttons whose text ends in Warning. |
/*[@text='Warning'] |
Identifies any element with the text Warning. |
/button[?'Warning'] |
Identifies buttons that have any attribute that contains the string Warning. |
/button[@text!=null()] |
Identifies buttons whose text attribute is not empty. |
/progressbar[@value>='13.5'] |
Identifies progress bars with a value greater than 13.5. Other possible operators: >, <, >=, <=. |
/button[@text=$var] |
Identifies buttons whose text has the value of the variable $var. |
/button[$var] |
Identifies the first, second, third, etc. button, depending on the numeric value of $var. |
/dom//input[#'Search'] |
Identifies an input element on a website (/dom for document object model) with the unique identifier Search. |
Functions
| Function | Description |
/table/row/cell[first()='True'] |
Identifies the first cell of a row. |
/table/row/cell[last()='True'] |
Identifies the last cell of a row. |
/table/row/cell[index()='2'] |
Identifies the second cell (refers to the position in the element tree). The index() function starts at 1. |
/table/row/cell[pos()='2'] |
Identifies the third cell (refers to the position in the element tree). The pos() function starts at 0. |
/form[x()>'100' and y()='100'] |
Identifies top-level applications with screen coordinates greater than 100 pixels. |
/form/button[cx()>'10' and cy()>'10'] |
Identifies buttons with client coordinates (= an element’s coordinates relative to its parent) greater than 10 pixels. |
/form[width()>'100' and height()>'100'] |
Identifies top-level applications with a width and height greater than 100 pixels. |
/dom/body/form/button[text()='Clear'] |
Identifies buttons on a website with the innertext Clear. For web testing, the function text() returns the value of the attribute innertext. |
/dom/body/form/[@id=null()] |
Identifies website forms whose ID attribute is not zero. |