Edit this Doc Automating Mobile Gestures With UiAutomator2 Backend

Touch actions are the most advanced and the most complicated way to implement any Android gesture. Although, there is a couple of basic gestures, like swipe, fling or pinch, which are commonly used in Android applications and for which it makes sense to have shortcuts, where only high-level options are configurable.

mobile: longClickGesture

This gesture performs long click action on the given element/coordinates. Available since Appium v1.19

Supported arguments

Usage examples

((JavascriptExecutor) driver).executeScript("mobile: longClickGesture", ImmutableMap.of(
    "elementId", ((RemoteWebElement) element).getId()
));
driver.execute_script('mobile: longClickGesture', {'x': 100, 'y': 100, 'duration': 1000})

mobile: dragGesture

This gesture performs drag action from the given element/coordinates to the given point. Available since Appium v1.19

Supported arguments

Usage examples

// Java
((JavascriptExecutor) driver).executeScript("mobile: dragGesture", ImmutableMap.of(
    "elementId", ((RemoteWebElement) element).getId(),
    "endX", 100,
    "endY", 100
));

mobile: flingGesture

This gesture performs fling gesture on the given element/area. Available since Appium v1.19

Supported arguments

Returned value

The returned value is a boolean one and equals to true if the object can still scroll in the given direction

Usage examples

// Java
boolean canScrollMore = (Boolean) ((JavascriptExecutor) driver).executeScript("mobile: flingGesture", ImmutableMap.of(
    "elementId", ((RemoteWebElement) element).getId(),
    "direction", "down",
    "speed", 500
));

mobile: pinchOpenGesture

This gesture performs pinch-open gesture on the given element/area. Available since Appium v1.19

Supported arguments

Usage examples

// Java
((JavascriptExecutor) driver).executeScript("mobile: pinchOpenGesture", ImmutableMap.of(
    "elementId", ((RemoteWebElement) element).getId(),
    "percent", 0.75
));

mobile: pinchCloseGesture

This gesture performs pinch-close gesture on the given element/area. Available since Appium v1.19

Supported arguments

Usage examples

((JavascriptExecutor) driver).executeScript("mobile: pinchCloseGesture", ImmutableMap.of(
    "elementId", ((RemoteWebElement) element).getId(),
    "percent", 0.75
));
can_scroll_more = driver.execute_script('mobile: pinchCloseGesture', {
    'elementId': element.id,
    'percent': 0.75
})

mobile: swipeGesture

This gesture performs swipe gesture on the given element/area. Available since Appium v1.19

Supported arguments

Usage examples

// Java
((JavascriptExecutor) driver).executeScript("mobile: swipeGesture", ImmutableMap.of(
    "left", 100, "top", 100, "width", 200, "height", 200,
    "direction", "left",
    "percent", 0.75
));

mobile: scrollGesture

This gesture performs scroll gesture on the given element/area. Available since Appium v1.19

Supported arguments

Returned value

The returned value is a boolean one and equals to true if the object can still scroll in the given direction

Usage examples

boolean canScrollMore = (Boolean) ((JavascriptExecutor) driver).executeScript("mobile: scrollGesture", ImmutableMap.of(
    "left", 100, "top", 100, "width", 200, "height", 200,
    "direction", "down",
    "percent", 3.0
));
can_scroll_more = driver.execute_script('mobile: scrollGesture', {
    'left': 100, 'top': 100, 'width': 200, 'height': 200,
    'direction': 'down',
    'percent': 3.0
})