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
| Parameter | Required | Description |
|---|---|---|
| Package Name | Yes | Package name of the target application. Leave empty ("") to search across all applications. |
| Candidate Texts | Yes | One or more text values separated using the pipe ( |
| Timeout | Yes | Maximum 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
- Creates a Search Text task.
- Waits for up to five minutes.
- Monitors the screen for any one of the specified completion messages.
- Executes the success callback immediately after one of the messages appears.
- 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.
Candidate text values must be separated using the pipe (|) character. The search succeeds when any one of the specified values is found.