Swipe
The Swipe action performs a swipe gesture in the specified direction. It is commonly used to navigate between screens, scroll through content, dismiss notifications, or reveal hidden UI elements. The swipe is performed relative to the device screen and does not require any coordinates.
When to Use
Use this action when you want to:
- Scroll through a list or page.
- Navigate between application screens.
- Open the notification panel.
- Dismiss notifications.
- Move through image galleries.
- Reveal additional content.
Syntax
var task = suremdmjs.automate().swipe(
"<Package Name>",
"<Direction>"
);
suremdmjs.automate().performAction(
task,
"onSuccess",
"onFailure"
);
Parameters
| Parameter | Required | Description |
|---|---|---|
| Package Name | Yes | Package name of the target application. Leave empty ("") to perform the gesture on the currently active screen. |
| Direction | Yes | Direction in which the swipe should be performed. |
Parameter Details
Package Name
Specifies the application where the swipe should be executed.
Example:
com.android.settings
To perform the gesture on the currently active screen, pass an empty string.
""
Direction
Supported values are:
- up
- down
- left
- right
Choose the direction based on the required navigation.
Example
The following example scrolls down through the Android Settings page.
!#suremdmjs
scrollSettings();
function scrollSettings() {
var task = suremdmjs.automate().swipe(
"com.android.settings",
"up"
);
suremdmjs.automate().performAction(
task,
"onScrollCompleted",
"onFailure"
);
}
function onScrollCompleted() {
suremdmjs.log("Settings page scrolled successfully.");
}
function onFailure() {
suremdmjs.log("Unable to perform swipe.");
}
How This Example Works
- Creates a Swipe task.
- Performs an upward swipe on the Android Settings screen.
- Waits until the gesture completes.
- Executes the success callback.
Expected Result
The screen scrolls upward, revealing additional settings.
Swipe performs a single gesture. If multiple swipes are required, execute additional Swipe actions from the success callback.