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
'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!