Tracking a ListItem with a @index keyword differs to ListItem[$index]

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
ajdin
Posts: 10
Joined: Wed Mar 20, 2019 11:04 am

Tracking a ListItem with a @index keyword differs to ListItem[$index]

Post by ajdin » Tue Jul 23, 2019 10:04 am

Hi,

I discovered this difference when refactoring recording modules which used the following versions of tracking a ListItem:
The first variant starts counting at 1, the second variant at 0 (which I assumed should be the case for the first variant as well).
Therefore, I am a bit confused. Should the indices in both variants start at 0?

Regards.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Tracking a ListItem with a @index keyword differs to ListItem[$index]

Post by Support Team » Tue Jul 23, 2019 9:14 pm

Hi ajdin,

While confusing, this is the expected behavior. Since RxPath is based on XPath (except it has 10+ years of enhancements built in), it is 1-based versus 0-based. element[n] will return the nth element found by the RxPath. element[@index=n] is telling Ranorex to look at the index attribute and ensure the number matches n. @index's value is dependent on the AUT and what it returns (often 0-based, but could be different). element[n] is based on Ranorex's RxPath and has nothing to do with what the AUT says the index is. Not all elements with have a @index attribute, but all elements can utilize [n] in the RxPath.

Here is a great explanation on why some things are 0-based and others 1-based (source):
Array and other collection indexes represent memory offsets, so logically enough they begin at zero. XML and XPATH indexes represent positions and counts, so logically enough they begin at one (and zero is therefore representative of "empty")
I hope this makes sense!

Cheers,
Ned

ajdin
Posts: 10
Joined: Wed Mar 20, 2019 11:04 am

Re: Tracking a ListItem with a @index keyword differs to ListItem[$index]

Post by ajdin » Wed Jul 24, 2019 8:37 am

Thank you for the clarification :)

BR.