Java-client: how to scroll to particular element automatically using Appium on iOS device

Created on 29 Jun 2016  路  8Comments  路  Source: appium/java-client

I am trying to automate a scenario, where I need to scroll to particular element in a list automatically. I have tried different scenarios but nothing worked

Appium version: 1.5.3
Programming Language: Java

question

All 8 comments

Look into finding the element using findElementByIosUIAutomation.

Then you can execute a UIAutomation script through executeScript and call scrollToVisible() at the end of it.

For example if you can find your element with:

String uiautoFind = "UIATarget.localTarget().frontMostApp().mainWindow()" +
        ".scrollViews()[0].cells().firstWithPredicate(\"name matches 'Sign In'\")"
driver.findElementByIosUIAutomation(uiautoFind);

Then call:

driver.executeScript(uiautoFind + ".scrollToVisible();");

I wrote this off the top of my head, so read up on UIAutomation docs when applying it to your case.

This is also very helpful: https://github.com/appium/appium/issues/2639

@ssynix Thank u very much for the reply.
I have tried the below code it worked for me
MobileElement fieldTwo = (MobileElement) driver.findElementsByClassName("UIATableCell").get(Result);
fieldTwo.click();

So I think thet it can be closed now.

I am getting below mentioned error when i am trying to scroll ,Can you please help.
My requirement i want to scroll to a element only using text.

Error:- Locator Strategy '-ios uiautomation' is not supported for this session

I get above mentioned when i use below mentioned approaches .I am using Appium 1.7.1

Approach 1:-
String uiautoFind = "UIATarget.localTarget().frontMostApp().mainWindow()" +
".scrollViews()[0].cells().firstWithPredicate(""+text+"")";
((IOSDriver) driver).findElementByIosUIAutomation(uiautoFind);

Approach 2:-
MobileElement table = driver.findElement(MobileBy
.IosUIAutomation(".tableViews()[0]"));
MobileElement slider = table.findElement(MobileBy
.IosUIAutomation(".scrollToElementWithPredicate("name CONTAINS '"+ text+"'")"));

Please reply at the earliest, on how do i solve this issue or let me know any other way or actual line of code to scroll to a text in ios app using appium 1.7.1 ,

@syedzubair1989 did you find the solution? I am also facing the same issue.

@chhavisingh , i tried a different approach ,i.e. scrolling to text in ios real device using java script executor, below mentioned is the actual code.

// scroll to text in ios

        JavascriptExecutor js = (JavascriptExecutor) driver;
        HashMap scrollObject = new HashMap<>();
        scrollObject.put("predicateString", "value == '" + text + "'");
        scrollObject.put("direction", "down");
             js.executeScript("mobile: scroll", scrollObject);

this will solve your issue, let me know if it worked for you or not.

@syedzubair1989, your solution works, thanks. Direction seems to be redundant.

Was this page helpful?
0 / 5 - 0 ratings