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.
Question
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+"\"));");