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?
Last item in list - RXPath
Re: Last item in list - RXPath
Hi,
There is a way to achieve what you want with simple xpath arguments.
Try for example this:
Eventually, you can use something like this:
Here are some more tricks you may find useful...
There is a way to achieve what you want with simple xpath arguments.
Try for example this:
This should return last available cell from the list of cells./container/list/cell[-1]
Eventually, you can use something like this:
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./container/list/cell[last()='True']
Here are some more tricks you may find useful...
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
Re: Last item in list - RXPath
Many thanks, that is a nifty trick!
Is /list/cell[pos()=2] different from /list/cell[2] ?
Is /list/cell[pos()=2] different from /list/cell[2] ?
Re: Last item in list - RXPath
You are welcome.
As for the difference between simple index and pos-based index, a picture is worth a thousand words... 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?
As for the difference between simple index and pos-based index, a picture is worth a thousand words... 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?

Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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