Direct scroll on iOS devices

When creating an automation script in Appium1.22.3 or later for an iOS device, you can achieve scrolling to a specific element on the screen by using a Perfecto extension to Appium's mobile:scroll command. The extension is an argument called direct that takes on a value of true. For an implementation example, see lines 6 and 7 in the following code snippet.

Note:

This extension only works when the toVisible argument is set to true.

Copy
WebElement element = driver.findElementByXPath("//*[@label='test']");
RemoteWebElement elementCast = (RemoteWebElement) element;
String elementID = elementCast.getId();
HashMap<String, Object> scrollObject = new HashMap<String, Object>();
scrollObject.put("elementId", elementID);
scrollObject.put("toVisible", true);
scrollObject.put("direct", true);
driver.executeScript("mobile: scroll", scrollObject);