Welcome to the Ranorex Support Portal

RanoreXPath syntax

On this page, you’ll find a list of the syntax expressions available. We’ll first cover axes and then attribute expressions.

Download

Reference


For more detailed examples of applied RanoreXPaths, please refer to ⇢ RanoreXPath examples.

Most of the examples on this page begin with /form, the role for top-level applications. Normally, you would further specify this role with an attribute, e.g. [@controlname='RxMainFrame'] for the Ranorex Studio Demo Application, but on this page we omit this to keep the RanoreXPaths short.

In this chapter

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.

List of axes

Syntax
child

Description
Returns all children of the context node.

Example

/form/child::button

Syntax
descendant

Description
Returns all descendants of the context node.

Example

/form/descendant::button

Returns all descendants of /form that have the role button.

Syntax
descendant-or-self | //

Description
Returns the context node and all its descendants.
For the abbreviated syntax //, further specification is optional.

Example

/form/descendant-or-self::button | /form//button

Only returns the descendants of /form that have the role button/formhas a different role and therefore isn’t returned. If it had the role button, it would also be returned.

Syntax
parent | ..

Description
Returns the parent of the context node.
In its abbreviated syntax, it must stand alone and does not accept further specification.

Examples

/form/button[@caption='OK']/parent::container

/form/button[@caption='OK']/..

Example 1: Returns the parent of the specified button element if it has the role container.
Example 2: Returns the parent of the specified button element, regardless of its role.

Syntax
ancestor

Description
Returns all ancestors of the context node.

Example

/form//button/ancestor::container

Finds all buttons that are descendants of /form and then returns all ancestors of these buttons that have the role container.

Syntax
ancestor-or-self

Description
Returns the context node and all its ancestors.

Example

/form//button/ancestor-or-self::container

Finds all buttons that are descendants of /form and then returns all ancestors of these buttons that have the role container. If the context node also had the role container, it would be returned as well.

Syntax
preceding-sibling

Description
Returns all siblings before the context node.

Example

/form/button[@caption='OK']/preceding-sibling::button

Returns all UI elements that have the role button, are siblings of the specified button, and come before it.

Syntax
following-sibling

Description
Returns all siblings after the context node.

Example

/form/button[@caption='OK']/following-sibling::button

Returns all UI elements that have the role button, are siblings of the specified button, and come after it.

Attributes


Download

Reference


You can also use regular expressions in RanoreXPaths. This is explained separately in
Ranorex Studio Expert > ⇢ Regular expressions in Ranorex Studio.

Syntax
/form

Description
Top-level applications usually have the role form. This syntax therefore identifies top-level applications.

Syntax
/form[@title='Calculator']

Description
Identifies top-level applications that have the title Calculator.

Syntax
/form[@title='Calculator' and @instance='2']

Description
Identifies the top-level application that has the title Calculator AND the instance attribute 2.

Syntax
/form[@title='Calculator' or @class='SciCalc']

Description
Identifies top-level applications that have the title Calculator OR the class SciCalc.

Syntax
/button

Description
Identifies UI elements that have the role button.

Syntax
/button[2]

Description
Identifies the second button (refers to the position in the element tree).

Syntax
/button[-2]

Description
Identifies the second-to-last button (refers to the position in the element tree).

Syntax
/button[@text='Exit']

Description
Identifies buttons with the text Exit.

Syntax
/button[@text!='Exit']

Description
Identifies buttons whose text attribute is not equal to Exit.

Syntax
/button[@text>'Warning']

Description
Identifies buttons whose text begins with Warning.

Syntax
/button[@text<'Warning']

Description
Identifies buttons whose text ends in Warning.

Syntax
/*[@text='Warning']

Description
Identifies any element with the text Warning.

Syntax
/button[?'Warning']

Description
Identifies buttons that have any attribute that contains the string Warning.

Syntax
/button[@text!=null()]

Description
Identifies buttons whose text attribute is not empty.

Syntax
/progressbar[@value>='13.5']

Description
Identifies progress bars with a value greater than 13.5. Other possible operators: ><>=<=.

Syntax
/button[@text=$var]

Description
Identifies buttons whose text has the value of the variable $var.

Syntax
/button[$var]

Description
Identifies the first, second, third, etc. button, depending on the numeric value of $var.

Syntax
/dom//input[#'Search']

Description
Identifies an input element on a website (/dom for document object model) with the unique identifier Search.

Functions


Syntax
/table/row/cell[first()='True']

Description
Identifies the first cell of a row.

Syntax
/table/row/cell[last()='True']

Description
Identifies the last cell of a row.

Syntax
/table/row/cell[index()='2']

Description
Identifies the second cell (refers to the position in the element tree). The index() function starts at 1.

Syntax
/table/row/cell[pos()='2']

Description
Identifies the third cell (refers to the position in the element tree). The pos() function starts at 0.

Syntax
/form[x()>'100' and y()='100']

Description
Identifies top-level applications with screen coordinates greater than 100 pixels.

Syntax
/form/button[cx()>'10' and cy()>'10']

Description
Identifies buttons with client coordinates (= an element’s coordinates relative to its parent) greater than 10 pixels.

Syntax
/form[width()>'100' and height()>'100']

Description
Identifies top-level applications with a width and height greater than 100 pixels.

Syntax
/dom/body/form/button[text()='Clear']

Description
Identifies buttons on a website with the innertext Clear. For web testing, the function text() returns the value of the attribute innertext.

Syntax
/dom/body/form/[@id=null()]

Description
Identifies website forms whose ID attribute is not zero.

USERS LOVE US

SUBSCRIBE TO OUR NEWSLETTER

Get the latest test automation information right in your mailbox.

FOLLOW US

© 2024 Ranorex GmbH. All Rights Reserved