copyTextFrom

Copy text content from a UI element to clipboard or variable.

The copyTextFrom command copies text from a UI element and stores it in memory. This command requires a Selector to identify the target element.

Accessing the copied text

When you copy content using the copyTextFrom command, you have two ways to use the text after it has been copied:

  1. Use the pasteText command to immediately insert the content into a focused field.

  2. To run an equality check, perform complex logic, or store the text for later use in your flow, use the maestro.copiedText variable.

Usage examples

The following examples demonstrate how to use the copied text.

Paste with the pasteText command

This example copies text from an element with the ID someId and pastes it into a search field.

appId: com.example.app
---
- launchApp
- copyTextFrom:
    id: "someId"
- tapOn:
    id: "searchFieldId"
- pasteText

Access with JavaScript

The copied text is available in JavaScript through the maestro.copiedText property. This example copies the text from someId and uses the inputText command to add the content into the search field.

Store and validate

You can assign the copied value to a custom variable to perform assertions or use it later in a Flow after other commands have overwritten the clipboard.

This example demonstrates how to copy text from a UI element, store the copied value in a variable using maestro.copiedText, and then validate that the captured text matches the expected value.

Explore how the pasteText command works, or learn how to use the available Selectors to define the desired element when copying content.

Last updated