Attempting to locate elements in a ListView in Android is THE MOST annoying thing ever.
It is fairly easy if:
- Your list only contains a single, common row type.
- Your list is so short it all fits on one screen (thus the XML remains unchanged if you try to scroll)
- Your list has no table groups (separators)
However, if your list is long, and has table groups (separators) it starts making it extremely difficult.
For example, I have a dynamic ListView similar to this. Any of the Separators may or may not be there. If any Separator group does exist, it will have one or more (effectively unlimited) Items.
If I simply want to get all of the Items without regard to if they belong to a particular Separator I can just use
@shermaneric logic - start at the top, gather all items on screen, scroll-gather-repeat until your last row data doesn't change. Works great.
However, if you want to find ONLY the items within a particular Separator things get extremely complicated.
For example, if I want to locate the Items for Separator 2 but Separator 1 has 50 items, the page will be so long the initial XML will not even include Separator 2. Not a huge issue, I'll simply have to scroll from the top of the list until I find Separator 2. That's easy using @shermaneric logic. Just to clarify, finding the Separator is easy. Gather its items is where the complication arrives.
To find specific Items that are related to each Separator I would normally use XPATH AXES which work perfectly.... until you scroll the page and your Separator(s) no longer exists in the XML.
For example, I want to locate all Items
android.widget.LinearLayout that exists under Separator 1
android.widget.TextView[@text='Separator 1'] you could use the following XPATH:
This works perfectly. But only on the first page/screen. In this example, assuming there's 100 Items under Separator 1 which will require a few screen scrolls to find them all. Once you scroll the page to find more Items under Separator 1 then the XML will no longer include Separator 1 and your XPATH AXES no longer function.
My current path is to craft some clever logic that scans the page for existence of my target Separator, and any other Separator, and dynamically composes an appropriate XPATH using various AXES. But my brain is starting to melt.
This would all be very much easier if each Item (table row) had a unique (but recurrent) resource-id or some other unique attribute I could search for such as @resource-id='separator1_row' and then @resource-id='separator2_row' but they don't, they're all effectively identical, and only differentiated by the Separator they fall under.
XPATH AXES work perfectly in iOS since the entire page XML is always provided regardless of how much data is out of view.
Soliciting your [hopefully better] ideas.