IOS handling collection views with many cell

With XCode8 and Appium 1.6

When trying to iterate through a list of cells (100+)
something like collectionview.findElements(By.className(“XCUIElementTypeCell”));

Takes for about 4 minutes to execute.
Is there a better / faster way to do this?
Previously with xCode7/appium 1.5 this only took a couple seconds.

Also we have to use XCUITest navigate through cells.
Is there any scrollTo functionality available? iosautomator had a scrollTo function that work pretty well. XCTest doesn’t seem to have a replacement for it.

Now if find the cell, and it’s index 120, how do i even scroll to it?

So, I must admit, my experience with xcode8 and Appium 1.6 so far has caused me to go back to Appium 1.5.3 for now. I still believe there are many issues with it and XCUITest to work out. And I’m okay for now letting all your guys go through them for me. :slight_smile: A big thanks for the front-line troopers!

Is there any reason you have to iterate through all the cells? Do you know the id/name of the cell you want beforehand?

:slight_smile:

Unfortunately, I need to get the nth cell of a collection view.
The collection view all have the same id, and are populated with dynamic content.

Ideally I would be able to get get the cells that are present on the screen, but unfortunately, that is not possible right now. As collectionview.findElements will gather all the cells and using a predicate find with wdVisible==1 doesn’t seem to work.

What happens if you try by xpath? Such as…

By.xpath("//XCUIElementTypeCell[100]")

returns error
also takes just as long as querying entire collection view

{“using”:“xpath”,“value”:"//XCUIElementTypeCell[10]"}
Enqueue Failure: UI Testing Failure - Failure fetching attributes for element

What does the GetPageSource() return? Does it show all the cells, visible or non-visible, with their proper values?

do not iterate but directly open needed cell (i did same as you and it damn slow with latest appium)

mine code now is:

el = ((IOSDriver) driver).findElementByIosNsPredicate(“value = ‘needed_value’”);

100 times faster :slight_smile:

if you want to scroll into it i do:

   try {
        tmpY = ((MobileElement) el).getCenter().getY();
        while (tmpY <= 0) {
            scrollToDirection_iOS(mainContainer.get(0), "u", 120);
            tmpY = ((MobileElement) el).getCenter().getY();
        }
        try{Thread.sleep(500);}catch (Exception e){} // complete scrolling animation
        return tapElement((MobileElement) el));
    } catch (Exception e) {
        e.printStackTrace();
    }

where scrollToDirection_iOS() and tapElement() - mine custom functions. you can use any instead.