Limiting search depth

Best practices, code snippets for common functionality, examples, and guidelines.
Posts: 4
Joined: Fri Sep 07, 2018 8:12 am

Limiting search depth

Post by MichielV » Fri Nov 09, 2018 10:12 am

We are building tests for a rather large WPF application (thousands of elements, 100+ nested levels) using ranorex.

In order to simplify the paths, we often use the "any descendants" vector //. This however has the downside that it significantly slows down the automation and spy because the entire AUT is traversed for each search.
We have been able to improve the performance by using a sequence of wildcards such as /?/?/?/?/?/?/?/?/?/?/ instead of //. However, this makes the paths less user-friendly to read.

So my questions are:
- is there any shorthand to combine multiple wildcards, e.g. /?[10]/ would search the first 10 levels from the root.
- is there an expression to get the first descendant encountered, that would stop further scanning of the application?
- any other recommendations to improve performance while maintaining an acceptible level of robustness?

User avatar
Ranorex Guru
Ranorex Guru
Posts: 4981
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Limiting search depth

Post by odklizec » Fri Nov 09, 2018 10:23 am


I'm afraid, the answer on first two questions is "no". There is no such functionality in Ranorex xpaths. You can create a feature request here: ... ve-ranorex

Probably the only way, how to improve the speed of element search, is to add some additional (ideally unique) elements to the xpath. E.g. search and select some additional "key" elements in the xpath and add them to the final xpath. Even if there are no elements with unique IDs, you can always find some elements with unique Class, InnerText or similar attributes. Additional elements could significantly improve the speed of search.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Limiting search depth

Post by krstcs » Mon Nov 12, 2018 3:30 pm

You should not use the "any descendants" vector ("//") unless absolutely necessary because this forces Ranorex to search the whole tree, which takes a lot of time depending on the system/application under test.

My suggestion would be to create rooted folders at intermediate levels that are pathed. This will allow Ranorex to only search for a limited number of elements instead of the whole tree. Your repo would look like:

MyApp -> form[@title='MyApp']
..RootedFolder1 -> */div[@id='123']
....Element1 -> */button[@title='Ok']
....Element2 -> */button[@title='Cancel']

Keep elements that are under the same parent in the same folder, then you only have to change the parent folder when the path changes and all children will have the new intermediate path.
Shortcuts usually aren't...