I am using Appium + Selenium + Java.

I am testing a native app and I sometimes need to scroll an element into view in order to click on it. It seems like, when testing a web app on iOS, you can use this to scroll. However, I am testing a native app and this doesn't seem to work.

I tested this solution with:

RemoteWebElement parent = (RemoteWebElement)driver.findElement(By.className("XCUIElementTypeTable")); //identifying the parent Table
String parentID = parent.getId();
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("element", parentID);

// Use the predicate that provides the value of the label attribute
scrollObject.put("predicateString", "label == '"+text+"'");
driver.executeScript("mobile:scroll", scrollObject);  // scroll to the target element

I found this proposed solution however, the "IosUIAutomation" or "findElementByIosUIAutomation" that we are supposed to use in this solution doesn't exist with my version of Appium + selenium.

I still managed to test it with:

String uiautoFind = "UIATarget.localTarget().frontMostApp().mainWindow()" +
                    ".scrollViews()[0].cells().firstWithPredicate(\"label = '"+text+"'\")";
((IOSDriver<MobileElement>)driver).findElementByIosNsPredicate("label = '"+text+"'");
((IOSDriver<MobileElement>)driver).executeScript(uiautoFind + ".scrollToVisible();");

But this solution didn't work either.


So, how can I scroll an element into view on an iOS native app?

Please note that, even though I am looking for the exact label on the example I gave, I would much prefer a solution where I would look for a "contain" and not an "equal".

As a side note, here is how I do it on Android (and it's working fine):

(MobileElement) ((AndroidDriver)driver).findElementByAndroidUIAutomator("new UiScrollable("
            + "new UiSelector().scrollable(true)).scrollIntoView("
            + "new UiSelector().textContains(\""+text+"\"));");

1 Answer 1


When I have tackled this in the past I used a loop and TouchActions. Treat the following sample as pseudo-code.

var element = driver.findElement(mySelector);
while(!element.IsPresent) {
    .press(100,100) // Start at 100,100
    .moveTo(200,200); // Passing absolute values of 200,200 ending up at 200,200
    element = driver.findElement(mySelector);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.