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
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();
You can refer this example: https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/ios/IOSScrollingSearchingTest.java & https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java
iOS Predicates: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/ios_predicate.md
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
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.
Most helpful comment
You can refer this example: https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/ios/IOSScrollingSearchingTest.java & https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java
iOS Predicates: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/ios_predicate.md