2

Is there a way to get the count of elements having same accessibilityID/label etc in Swift?

Arjun Kalidas
  • 919
  • 9
  • 14

2 Answers2

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:

  1. 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 atIndexwith 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.
  2. Expose their private method matchedElementsWithTimeout:error: but you will risk being broken if they rename it.
khandpur
  • 705
  • 3
  • 12
0

I think that there is much better solution that google provides right in EarlGrey repo. Follow this link.

Mysiaq
  • 555
  • 4
  • 13