Is there a way to get the count of elements having same accessibilityID/label etc in Swift?
Asked
Active
Viewed 542 times
2 Answers
1
Not easily. It may be worth filing a feature request for it. In the mean time, Here are some options, each having their own drawbacks:
- EarlGrey added API called atIndex which lets you select a single element from a list of multiple matched elements but this list is not exposed. You could try something like calling
atIndex
with a no-op assertion in a loop and increment a counter on each successful assertion. When the assertion fails, you know that's when index went out of bounds. It will essentially give you the count but it will be very slow and inefficient as it will scan the UI hierarchy each time you run the assertion. - Expose their private method matchedElementsWithTimeout:error: but you will risk being broken if they rename it.

khandpur
- 705
- 3
- 12
-
Did my suggestion above help? – khandpur Oct 24 '16 at 19:22