Appium IOS: XCUIElementTypeTable automatically scrolls when findelement is called

I’m currently testing out an app that has several XCUIElementTypeCell in an XCUIElementTypeTable. I search for a specific text from the table and click the specific list. Once I click it, the XCUIElementTypeCell expands, showing several items for me to interact with, one of which is a button that shows another screen.

Whenever I try to do a findelement to the button that needs to be clicked, the whole UI scrolls down, causing the test script to fail since the button is no longer in view. Any reason as to why this is happening?

To add, it seems to only happen when interacting with cells found way below the list/table. It doesn’t happen when selecting the first several cells that appear upon loading.

this is an issue related to your xpath, use more effective xpaths for working with the elements.

We’re already using the correct locator for it. We even tried using accessibility id and class chain and the results are the same. It doesn’t just happen on findelement, even when using the inspector the tableview suddenly scrolls as long as the cell selected is not from the first several shown upon loading, rendering the button to be out of view for appium to click.

As I stated above, it doesn’t happen when selecting the first few cells displayed upon loading. It only happens when selecting cells found further below the table view.

create a scroll method, in which firstly you have to check the visibility of your target element, if element found then click on it and if not, then scroll according to your requirement

Already tried that approach as well. Problem with it is that when the view scrolls, the button we need to select randomly appears at the top or at the bottom of where appium automatically scrolled to.

The scrolling triggers the moment a command is called to appium, so we we’re thinking it’s a bug with appium. This issue only occurs on the view with XCUIElementTypeTable and doesn’t happen anywhere else on the app.

can you please show me your code snippet or video, so that I can try to help you, as we are also doing the same and having no issue with working on XCUIElementTypeTable

Here’s a code snippet of what we’re currently using:

                string visibleClassChain = string.Format("**/XCUIElementTypeStaticText[`name=='labelCell' AND value CONTAINS[cd] '{0}' AND visible == true`]", cellToSelect);
                while (!Application.ElementExistByClassChain(visibleClassChain))
                {
                    Utility.ScrollIOSScreen();
                }
                
                var cellToSelect = Application.FindElementByClassChain(visibleClassChain, "cell to select");                    
                Command.Click(cellToSelect , "Click cell");

                var detail = Application.FindElementByClassChain("**/XCUIElementTypeButton[`name=='ButtonDetails'`]", "Details button"); /*<-- Screen scrolls here if cell selected is not from the first cells shown upon load / from way below the list*/
                Command.Click(detail, "Details click");

Command.Click simply does the following:

    public static void Click(IOSElement element, string name)
    {
        try
        {
            driver.Tap(1, element, 200);
        }
        catch (Exception ex)
        {
            throw new ApplicationException("Unable to click " + name, ex);
        }
    }

Utility.ScrollIOSScreen simply does a driver.swipe to the screen to show the next cells.

FindElementByClassChain’s implementation is below:

    public static IOSElement FindElementByClassChain(string classChain, string elementName)
    {
        try
        {
            return driver.FindElement("-ios class chain", classChain);
        }
        catch (Exception e)
        {
            if (elementName == "")
            {
                var elementId = classChain.ToString().Split(new string[] { ":" }, StringSplitOptions.None);
                elementName = elementId.Last().Trim();
            }
            throw new Exception(string.Format("{0} element was not found", elementName), e);
        }
    }

have you tried with other alternative ways to scroll your screen ?

I suggest you to use TouchActions, instead of sriver.swipe

hi shubham,

Like i said, the issue isn’t with the scroll method, but with Appium doing a scroll when using findelement.

hi @ervinchan,
Have you found a workaround? have the same issue with an inverted list of cells where the first cell is at the bottom.

@ervinchan I am currently running into similar issue and wonder if you have found any solution or workaround on this?