Search code examples
appiumappium-iosappium-android

Is it possible to scroll to an element using something similar in iOS like AndroidUIAutomator?


As the title already suggests this is about scrolling in Appium in an native iOS application. In the Android app we use this:

MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()" +
     ".scrollable(true)).scrollIntoView(new UiSelector().resourceId(\"" + myVariable +\""));");

This works well for our Android app and I was wondering if there is something similar that can be used for iOS. Is there maybe the option to use this method?

MobileBy.iOSClassChain()

I have no experience with it and I don't find anything in the documentation that tells me if there is a way to scroll to an element using this method with an option to enable or passing it through within the string that is passed to it. Is it just a faster way to locate elements instead of XPath or could it be used in a similar way as AndroidUIAutomator?

The above mentioned method for Android is much more reliable and faster than any touchAction which we used before and therefore I would like to switch to something similar in iOS as well.


Solution

  • The recommended best practice for performing controlled scrolling is using the Appium “mobile:scroll” script command. This command is performed using the executeScript() method.

    RemoteWebElement element = (RemoteWebElement)driver.findElement(By.className("XCUIElementTypeTable"));
    String elementID = element.getId();
    HashMap<String, String> scrollObject = new HashMap<String, String>();
    scrollObject.put("element", elementID); // Only for ‘scroll in element’
    scrollObject.put("direction", "down");
    driver.executeScript("mobile:scroll", scrollObject);
    

    “element”: The id of the element that you want to scroll – “element” must be scrollable.

    “direction”: “up”, “down”, “left, “right”.

    For more information about scrolling, check Scrolling in IOS