TouchAction for swipe is not working in iOS

Hi,

I am using below code the perform vertical swipe on the screen, but the swipe action is not performing:

Dimension size = driver.manage().window().getSize();
int endPoint = (int) (size.height * 0.80);
int startPoint = (int) (size.height * 0.40);
int anchor = size.width/3;
new TouchAction(driver).press(anchor, startPoint).waitAction(Duration.ofSeconds(1)).moveTo(anchor, endPoint).release().perform();

Environment:
iOS: 10.3
XCode: 9.1
Appium version: 1.7.1 & 1.7.2

But when see in the appium log, I am seeing my coordinates are doubled when calling WDA dragfromtoforduration method. Below is the appium log:

[HTTP] --> POST /wd/hub/session/3a35959c-ee80-401b-96a9-f7c455576dfe/touch/perform {“actions”:[{“action”:“press”,“options”:{“x”:125,“y”:266}},{“action”:“wait”,“options”:{“ms”:0}},{“action”:“moveTo”,“options”:{“x”:125,“y”:533}},{“action”:“release”,“options”:{}}]}
[MJSONWP] Calling AppiumDriver.performTouch() with args: [[{“action”:“press”,“options”:{“x”:125,“y”:266}},{“action”:“wait”,“options”:{“ms”:0}},{“action”:“moveTo”,“options”:{“x”:125,“y”:533}},{“action”:“release”,“options”:{}}],“3a35959c-ee80-401b-96a9-f7c455576dfe”]
[XCUITest] Executing command ‘performTouch’
[XCUITest] Received the following touch action: press(options={“x”:125,“y”:266})-wait(options={“ms”:0})-moveTo(options={“x”:125,“y”:533})-release(options={})
[XCUITest] Found matching gesture: drag
[JSONWP Proxy] Proxying [POST /wda/dragfromtoforduration] to [POST http://localhost:8100/session/4235AB4E-6FC0-4CD8-8C46-A9855753CE0E/wda/dragfromtoforduration] with body: {“fromX”:125,“fromY”:266,“toX”:250,“toY”:799,“duration”:0}
[JSONWP Proxy] Got response with status 200: {“value”:{},“sessionId”:“4235AB4E-6FC0-4CD8-8C46-A9855753CE0E”,“status”:0}
[MJSONWP] Responding to client with driver.performTouch() result: null
[HTTP] <-- POST /wd/hub/session/3a35959c-ee80-401b-96a9-f7c455576dfe/touch/perform 200 1403 ms - 76

open new issue under https://github.com/appium/appium/issues

try new TouchAction(driver).press(anchor, startPoint).moveTo(anchor, endPoint).release().perform();

As x-axis and y-axis (starts from top left of the screen) start position is different from Android, I had to update my code to work on iOS.

Below is the code working for me:

Dimension size = driver.manage().window().getSize();
int endPoint = (int) (size.width * 0.20);
int startPoint = (int) (size.width * 0.80);
int anchor = size.height/2;
new TouchAction(driver).press(anchor, startPoint).waitAction(Duration.ofSeconds(0)).moveTo(anchor, endPoint).release().perform();

1 Like

Scroll down-

(new TouchAction(driver())).press(x1, y1).moveTo(-x2, -y2).release().perform();

Scroll up-

(new TouchAction(driver())).press(x1, y1).moveTo(x2, y2).release().perform();

1 Like

See if this helps i am working with latest appium on iOS