Skip to main content

Scroll Until Click with Timeout

The Scroll Until Click with Timeout action scrolls the screen in the specified direction until the target element becomes visible. Once found, the element is clicked automatically. Unlike Scroll Until Click, this action allows you to specify a custom timeout, controlling how long the automation should continue searching for the target element before failing. This action is useful when navigating long lists, settings pages, or dynamically loaded content where the target element may take additional time to appear.

When to Use​

Use this action when you want to:

  • Locate and open an option in a long settings page.
  • Select an item from a dynamically loaded list.
  • Navigate through application menus that require multiple scrolls.
  • Specify a maximum waiting time for locating an element.

Syntax​

var task = suremdmjs.automate().scrollUntilClick(
"<Package Name>",
"<Direction>",
"<Element Text>",
<Timeout in Milliseconds>
);

suremdmjs.automate().performAction(
task,
"onSuccess",
"onFailure"
);

Parameters​

ParameterRequiredDescription
Package NameYesPackage name of the target application. Leave empty ("") to search all applications.
DirectionYesScroll direction. Supported values are up, down, left, and right.
Element TextYesVisible text of the element to locate and click.
TimeoutYesMaximum time, in milliseconds, to search for the element before the action fails.

Parameter Details​

Direction​

Supported values:

  • up
  • down
  • left
  • right

Choose the direction based on where the target element is expected to appear.

Timeout​

Specifies how long the automation should continue searching for the target element.

ValueDescription
5000Waits for up to 5 seconds.
20000Waits for up to 20 seconds.
60000Waits for up to 60 seconds.

Example​

The following example scrolls through the Android Settings screen for up to 60 seconds 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",
60000
);

suremdmjs.automate().performAction(
task,
"developerOptionsOpened",
"optionNotFound"
);
}

function developerOptionsOpened() {
suremdmjs.log("Developer Options opened successfully.");
}

function optionNotFound() {
suremdmjs.log("Developer Options could not be located within 60 seconds.");
}

How This Example Works​

  1. Starts scrolling downward through Android Settings.
  2. Searches for the Developer Options menu.
  3. Continues scrolling until the element is found or the 60-second timeout is reached.
  4. Clicks Developer Options automatically when found.
  5. Executes the success callback if the action succeeds, or the failure callback if the element cannot be located within the specified timeout.

Expected Result​

The Developer Options page opens automatically if the target element is found within 60 seconds. Otherwise, the failure callback is executed.

note

The timeout specifies the maximum duration allowed for the search operation. If the target element is found earlier, the automation clicks it immediately without waiting for the remaining time.

💬 Help us improve this documentation

Was this information useful?

Your feedback helps us keep our documentation accurate, up to date, and useful.