Cant scroll ios list

I have list of countries in my app which I want to scroll to specific country and tap. Android provides UIAutomator to scroll, for IOS I tried:

public void tapOnElementByText(By locator, String element) {
        HashMap<String, Object> scrollObject = new HashMap<>();
        JavascriptExecutor js = driver;
        String elementId = driver.findElement(locator).getId();
        scrollObject.put("element", elementId);
        scrollObject.put("name", element);
        scrollObject.put("direction", "down");
        js.executeScript("mobile: scroll", scrollObject);

It’s simply not working, my automation strategy is XCUITest. Any suggestions how to scroll app?

try first ->

BTW in many cases in iOS works very fast use of setValue for XCUIElementTypePickerWheel element.

didn’t had luck with it, I need something like UIAutomator in android where I can scroll screen till text or element id, with my code above it’s not working.

Show screen of your country list. How you tried setValue code and page source of screen.

What you have tried from above tutorial link?

Resolved the issue with this code:

public void tapOnElementByText(String element) {
        HashMap<String, String> scrollObject = new HashMap<>();

        JavascriptExecutor js = driver;
        scrollObject.put("direction", "down");
        js.executeScript("mobile: scroll", scrollObject);
        try {
            driver.findElementByIosNsPredicate("label == \""+element+"\"").click();
        } catch (NoSuchElementException exception){
            System.out.println("Element not found");

Slowly but will work. All good.

1 Like