Skip to main content

Search Text

The Search Text action waits until one or more specified text values appear on the screen. The action succeeds as soon as any one of the specified text values is found. Unlike Click Element, this action does not interact with the UI. Instead, it is commonly used to verify that a particular screen, message, or operation has completed before continuing with the next automation step.

When to Use

Use this action when you want to:

  • Wait for an application installation to complete.
  • Verify that a success or error message is displayed.
  • Wait for a loading screen to finish.
  • Detect whether a particular screen has opened.
  • Continue the automation only after a specific text appears.

Syntax

var task = suremdmjs.automate().search(
"<Package Name>",
"<Candidate Texts>",
<Timeout in Milliseconds>
);

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

Parameters

ParameterRequiredDescription
Package NameYesPackage name of the target application. Leave empty ("") to search across all applications.
Candidate TextsYesOne or more text values separated using the pipe (
TimeoutYesMaximum time, in milliseconds, to wait before the search fails.

Parameter Details

Package Name

Specifies the Android package containing the target screen.

Example: com.android.packageinstaller

Leave this empty to search all currently visible applications.

Candidate Texts

Specify one or more possible text values. Separate multiple values using the pipe (|) character.

Example:

Installation Complete|App Installed|Done

The automation succeeds if any one of these values appears on the screen.

Timeout

Specifies the maximum amount of time to wait.

Example:
300000

Waits for 5 minutes before the action fails.

Example

The following example waits up to five minutes for an application installation to complete.

!#suremdmjs

waitForInstallation();

function waitForInstallation() {

var task = suremdmjs.automate().search(
"",
"Installation complete|App installed|Done",
300000
);

suremdmjs.automate().performAction(
task,
"installationCompleted",
"installationFailed"
);

}

function installationCompleted() {
suremdmjs.log("Application installed successfully.");
}

function installationFailed() {
suremdmjs.log("Installation did not complete within the specified time.");

}

How This Example Works

  1. Creates a Search Text task.
  2. Waits for up to five minutes.
  3. Monitors the screen for any one of the specified completion messages.
  4. Executes the success callback immediately after one of the messages appears.
  5. Executes the failure callback if none of the messages appear before the timeout expires.

Expected Result

The automation continues only after an installation completion message appears.

note

Candidate text values must be separated using the pipe (|) character. The search succeeds when any one of the specified values is found.

💬 Help us improve this documentation

Was this information useful?

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