简体   繁体   中英

How to Swipe in iOS using Appium

I am trying to swipe down a modal view in iOS using Appium with java.

I have tried this two ways unsuccessfully:

JavascriptExecutor js2 = (JavascriptExecutor) driver;

 HashMap<String, String> scrollObject2 = new HashMap<String, String>();
 scrollObject2.put("x", "200");
 scrollObject2.put("y", "550");
 scrollObject2.put("direction", "down");
 js2.executeScript("mobile: swipe", scrollObject2);

 TouchAction action = new TouchAction(driver);
 action.press(PointOption.point(200, 550)).moveTo(PointOption.point(200, 700)).release().perform();

What I am doing wrong? is another correct way to achieve this?

Thanks!

You should do it using js script executor.

No need to add coordinates like you did, just try something like this:

HashMap<String, String> scrollObject = new HashMap<>();
JavascriptExecutor js = driver; 
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject); //or "mobile: swipe"
public static void fingerSwipe(int startX, int startY, int endX, int endY, long timeInMillis){
PointerInput touchAction = new PointerInput(PointerInput.Kind.TOUCH, "touchAction");
Interaction moveToStart = touchAction.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), startX, startY);
Interaction pressDown = touchAction.createPointerDown(PointerInput.MouseButton.LEFT.asArg());
Interaction moveToEnd = touchAction.createPointerMove(Duration.ofMillis(timeInMillis), PointerInput.Origin.viewport(), endX, endY);
Interaction pressUp = touchAction.createPointerUp(PointerInput.MouseButton.LEFT.asArg());

Sequence swipe = new Sequence(touchAction, 0);
swipe.addAction(moveToStart);
swipe.addAction(pressDown);
swipe.addAction(moveToEnd);
swipe.addAction(pressUp);

driver.perform(Arrays.asList(swipe));

}

I use selenium interactions package to perform a swipe using JAVA and appium. Try using something similar to above code in WebDriverIo for Appium versions - 1.15.0 and above. You just need to pass input parameters depending upon the swipe you want to perform.

'long timeInMillis' is the time period of the swipe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM