Scroll Until Click
The Scroll Until Click action scrolls the screen in the specified direction until the target element becomes visible. Once found, the element is clicked automatically. This action is particularly useful for navigating long lists, settings pages, and menus where the required option is not initially visible.
When to Use
Use this action when you want to:
- Open an option located further down a Settings page.
- Select an item from a long list.
- Navigate through application menus.
- Scroll until a configuration option becomes visible.
Syntax
var task = suremdmjs.automate().scrollUntilClick(
"<Package Name>",
"<Direction>",
"<Element Text>"
);
suremdmjs.automate().performAction(
task,
"onSuccess",
"onFailure"
);
Parameters
| Parameter | Required | Description |
|---|---|---|
| Package Name | Yes | Package name of the target application. Leave empty ("") to search all applications. |
| Direction | Yes | Direction in which to scroll. Supported values are up, down, left, and right. |
| Element Text | Yes | Visible text of the element to locate and click. |
Parameter Details
Direction
Supported values:
up
down
left
right
Choose the direction based on where the target element is expected to appear.
Example
The following example scrolls through the Android Settings screen until the Developer Options menu becomes visible, then opens it.
!#suremdmjs
openDeveloperOptions();
function openDeveloperOptions() {
var task = suremdmjs.automate().scrollUntilClick(
"com.android.settings",
"down",
"Developer Options"
);
suremdmjs.automate().performAction(
task,
"developerOptionsOpened",
"optionNotFound"
);
}
function developerOptionsOpened() {
suremdmjs.log("Developer Options opened successfully.");
}
function optionNotFound() {
suremdmjs.log("Developer Options could not be located.");
}
How This Example Works
- Starts scrolling downward.
- Continuously searches for Developer Options.
- Stops scrolling when the option becomes visible.
- Clicks the option automatically.
- Executes the success callback.
Expected Result
The Developer Options page opens automatically.
If the target element cannot be found after the scroll operation reaches the end of the available content, the failure callback is executed.