How to get number of element with same name in iOS

i use RF+Appium
there are so many search result need to scroll several times, i would like to get the number of some items, and click each of them, like"Shell", i get the number use xpath: Get Matching Xpath Count | //XCUIElementTypeStaticText[@name=“Shell”], click each of them use: xpath=(//XCUIElementTypeStaticText[@name=“Shell”])[i]
the problem is :

  1. work slow
  2. will be no response when result is too many
    is there a better way ?

@Lily11 switch to nspredicate. 10 times faster comparing xpath.

@Aleksei, thank you reply so soon! other element i use nspredicate, but in my situation, i need to iterate all items named"Shell", click every “Shell” and verify some detail text, how to use nspredicate by index?

@Lily11 how about:

        List<MobileElement> elements = driver.findElements(MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeStaticText' AND label == 'your_label_text'");

@Aleksei, thank you, i found another way, i use Get Webelements to put nsp=type==“XCUIElementTypeStaticText” AND name==“Shell”
in to list a, then click every “Shell” via a[i]

Who the speed issue fixed?

yes, this work faster! there is a new problem puzzles me:pensive:
in current screen only include three element that named ‘Shell’, when click a[4], will no response in app, but run result is successful, it seems like can’t found a[4], it is strange that can’t click a[4] also after swipe until a[4] is visible

Remember in iOS we can see elements outside screen. Thus if wr want tap on it - we need scroll first. With android we can see only elements which are on screen.

Get number of elements before you scroll. Are you visible all 4? There is a possibility that app dynamically adds new cells while you scroll.

Thank you so much! @Aleksei

In Android, actually, it is possible, but with Espresso driver only. Check

Yes. But we need add it to test build. Maybe when UiAutomator2 will stop work…

I’ve get a better way! step1: i got the number of tab cells and every screen cells show, step2: calculating the scrolling times based on step1 and put the scrolling times in a for loop, step3: in for loop, get the number of element named “Shell” in each screen. i’m so happy that resolved this situation perfect!

well - glad you succeed. final solution is always a bit different and depends on app.