How to use TouchAction for press + move + hold + release gesture

Hi all,

I need to implement some complicated gesture. I need to press some element, move it to another element, hold 5 seconds(in this case some required context menu will be appeared), and release it.

The only way I found to get it working is

touchAction.longPress(FirstElement, Duration.ofSeconds(30)).moveTo(TwoElement.getCenter().x, TwoElement.getCenter().y + 45).release().perform();

In this case the movement is so slow and it’s enough to get context menu appeared. But it makes test case very slow and it’s not acceptable for us.

I’ve tried to do below touch action, as it looks more appropriate for my case, but it doesn’t work at all.

touchAction.longPress(FirstElement, Duration.ofSeconds(1)).moveTo(TwoElement.getCenter().x, TwoElement.getCenter().y + 45).waitAction(Duration.ofSeconds(2)).release().perform();

Please help me to get it working.

@aozolin you did not write how you create touchAction but should be like:

new TouchAction((MobileDriver) driver).press(FirstElement).waitAction(Duration.ofMillis(duration)).moveTo(endx, endy).release().perform();

try above waitAction …

Thanks Aleksei.

Here is my code:

TouchAction touchAction = new TouchAction(( driver);
touchAction.longPress(FirstElement, Duration.ofSeconds(15)).moveTo(endx,

I’ve tried your one, but it works the same way as my one above.
And I need to do a wait action after move action and before a release. In the above example the wait action affects a move action only.

So I just see that element is moving faster or slowly, and no any waits before the release.

@aozolin give a try of idea to make third TINY move :slight_smile:

new TouchAction((MobileDriver) driver).press(FirstElement).waitAction(Duration.ofMillis(duration)).moveTo(endx, endy).waitAction(Duration.ofMillis(duration)).release().perform();
// or
new TouchAction((MobileDriver) driver).press(FirstElement).waitAction(Duration.ofMillis(duration)).moveTo(endx, endy).waitAction(Duration.ofMillis(duration)).moveTo(minor_x, minor_y).release().perform();

@Aleksei, thank you. I’ve tried both options. The result is below:

When I use my code

TouchAction touchAction = new TouchAction(( driver);
touchAction.longPress(FirstElement, Duration.ofSeconds(15)).moveTo(endx,

I see that fist element is pressed and it’s moving on the screen to another element, but it releases the hold without any waits, and context menu is not appeared.

When I use your options, for both the same behaviour - nothing just happens on the screen, no context menu appears at all.

This is a long shot, but try without the release at the end:

new TouchAction((MobileDriver) driver).press(FirstElement).waitAction(Duration.ofMillis(duration)).moveTo(endx, endy).perform();

@Telmo_Cardoso, still no luck.
Nothing happens on the screen in this case.

Is this for Android… Do you know of any app in the store that has same behavior. I wouldn’t mind give it a try :smiley: on some ideas

@aozolin did you enable on phone/emulator in development menu to show touches and see what actually happend on phone? It is veru helpfull.

If you are using the latest beta java client, the API has been changed. Here is the new implementation

@pr4bh4sh, I’m using not the latest version now.
I’ve tried to use a new one, but it still doesn’t work.

It looks like appium doesn’t support such actions as I need.

A hacky way to make Appium hold after moving is:
Press el1 → Move to el2 → Keep move to el2 to hold with specific time → Move to el3 → Release & Perform

TouchAction touchAction = new TouchAction(driver);