0
votes

I want to know the difference between Tapping and pressing on an element while using Appium Driver.

I was able to understand the difference between Click and Tap but not able to clear my head about tap and press. Only difference I was able to ascertain was tap works with both positions and element but press seems to work only with position.

But even then I can use tap to handle both position clicks and element clicks. Why do we need press explicitly ? They seem to perform the same function on UI. Can someone please explain me a use case where we need to go explicitly for tap and not press and vice-versa.

Below is the code I am using for both :

Tapping:

t.tap(tapOptions().withElement(ElementOption.element(MY_WEBELEMENT))).perform();

Pressing:

t.press(PointOption.point(0, 1200)).release().perform();

I am new to Appium testing and still working on improving these basics. Feel free to guide me to any existing documentation in place as well.

1

1 Answers

1
votes

Tap and Press both works on Element and Coordinate. Have a look.

Suppose I have this Mobile element, coordinates and duration.

MobileElement myElement;
    int xPoint, int yPoint;
    int duration = XXXX; //in miliseconds

Tap on Element:

new TouchAction(localdriver).tap(tapOptions().withElement(element(myElement))).perform();

Tap on Coordinates:

new TouchAction(localdriver).tap(point(xPoint, yPoint)).perform();

Tap on Element using coordinates relative to element:

new TouchAction(localdriver).tap(tapOptions().withElement(element(myElement, xPoint, yPoint))).perform();

LongPress on Element:

new TouchAction(localdriver).longPress(longPressOptions().withElement(element(myElement))).release().perform();

LongPress on Element with Duration:

new TouchAction(localdriver).longPress(longPressOptions().withElement(element(myElement)).withDuration(Duration.ofMillis(duration))).release().perform();

LongPress on coordinates:

new TouchAction(localdriver).longPress(point(xPoint, yPoint)).release().perform();