This documentation is deprecated. Please refer to appium-uiautomator2-driver repository

  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: doubleClickGesture

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

Supported arguments

Usage examples

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

mobile: clickGesture

This gesture performs click action on the given element/coordinates. Available since Appium UiAutomator2 driver 1.71.0. Usage of this gesture is recommended as a possible workaround for cases where the "native" tap call fails, even though tap coordinates seem correct. This issue is related to the fact these calls use the legacy UIAutomator-based calls while this extension is based on the same foundation as W3C does.

Supported arguments

Usage examples

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

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
})