Last item in list - RXPath

Ranorex Studio, Spy, Recorder, and Driver.
loonquawl
Posts: 69
Joined: Wed Nov 22, 2017 10:08 am

Last item in list - RXPath

Post by loonquawl » Tue Nov 20, 2018 12:34 pm

I currently have to pick an item from a list. If i was to pick the first item, this would be easy, also if i only had to pick a certain numeric position: the RXPath for the second thing would simply read, for instance /container/list/cell[2].

Now i'd like to pick the last one, whatever the last one is - i currently have a small user code snippet to do that, by getting all cells, and then basically picking cell[len(cells)] - Is there a way to do this as a path, without having to intercede with usercode?

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

Re: Last item in list - RXPath

Post by odklizec » Tue Nov 20, 2018 1:31 pm

Hi,

There is a way to achieve what you want with simple xpath arguments.
Try for example this:
/container/list/cell[-1]
This should return last available cell from the list of cells.
Eventually, you can use something like this:
/container/list/cell[last()='True']
These xpath tricks got lost from the Ranorex user guide, during its overhaul to a new online format. I already reported this omission to Ranorex support.
Here are some more tricks you may find useful...
xpath_examples.png
You do not have the required permissions to view the files attached to this post.
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

loonquawl
Posts: 69
Joined: Wed Nov 22, 2017 10:08 am

Re: Last item in list - RXPath

Post by loonquawl » Tue Nov 20, 2018 2:12 pm

Many thanks, that is a nifty trick!

Is /list/cell[pos()=2] different from /list/cell[2] ?

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

Re: Last item in list - RXPath

Post by odklizec » Tue Nov 20, 2018 2:42 pm

You are welcome.

As for the difference between simple index and pos-based index, a picture is worth a thousand words...
indexes.png
Basically, simple index returns first (and only) element returned by the xpath and pos returns (each) first item (childindex-based) from the list of items returned by the xpath.

BTW, don't be confused by the fact, that the above picture shows "Automation Tools" for pos()=1, while it appears to be a second item in the middle list of items. It's because the Automation Tools item has ChildIndex=1, while the other "second items" have ChildIndex=2. Don't ask me why? :D
You do not have the required permissions to view the files attached to this post.
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