Hi,
How to use newly provided mobile commands with tap and scroll?
Commands are found here.
But I dont know how to use them with java.
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/ios-xctest-mobile-gestures.md
I have used scroll,
//Swipe and load content
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "left");
//scrollObject.put("element", ((RemoteWebElement)).getId());
js.executeScript("mobile: swipe", scrollObject);
And for scroll,
driver.executeScript("mobile", "scroll", "direction" , "down");
With tap also,
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("X", 200);
params.put("Y", 200);
driver.executeScript("mobile: tap", params);
public boolean tapElement_XCTest(MobileElement el) {
try {
// tap into center of element
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> tapObject = new HashMap<String, String>();
tapObject.put("x", String.valueOf(el.getSize().getWidth() / 2));
tapObject.put("y", String.valueOf(el.getSize().getHeight() / 2));
tapObject.put("element", el.getId());
js.executeScript("mobile:tap", tapObject);
return true;
} catch (Exception e) {
return false;
}
}
public boolean swipeToDirection_iOS_XCTest(MobileElement el, String direction) {
try {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> swipeObject = new HashMap<String, String>();
if (direction.equals("d")) {
swipeObject.put("direction", "down");
} else if (direction.equals("u")) {
swipeObject.put("direction", "up");
} else if (direction.equals("l")) {
swipeObject.put("direction", "left");
} else if (direction.equals("r")) {
swipeObject.put("direction", "right");
}
scrollObject.put("element", el.getId());
js.executeScript("mobile:swipe", swipeObject);
return true;
} catch (Exception e) {
return false;
}
}
@Aleksei please clarify which location strategy do you use for MobileElement el on iOS 11 ?
why do you do action e.getId( ) ?
@VikramVI
- this is element. no matter how you find it. any strategy. In page object you just calling it as:
someEl = driver.findElement....
// or maybe your element was in annotation like:
@AndroidFindBy(className = "android.widget.TextView")
private AndroidElement someEl ;
tapElement_XCTest(someEl);
- with el.getId() is just required by “mobile:swipe”
more to read: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/touch-actions.md
Thanks for the clarification.