Text Element Module (ui_element)
This module is available in versions after 20260507
ui_element reads UI elements from the current screen by text, role, state, or coordinate, and performs actions such as click, scroll, text input, toggle, and adjustment on matched elements. It is useful when scripts need to understand the current UI, reduce hard-coded coordinates, or keep readable targeting logic across devices.
For fixed-coordinate touch operations, prefer the Touch Module. Coordinates exposed by ui_element are physical pixels.
Basic Usage
local ui_element = require("ui_element")
local item, err = ui_element.find({
title = "Search",
role = "text_field",
})
if item then
ui_element.input_text(item, "hello")
else
sys.toast(err)
end
Description
Query APIs usually return
nil, erron failure.find_allreturns an empty array when no element matches. Action APIs returntrue, infoon success andnil, erron failure. After the UI changes, a previous snapshot no longer represents the latest screen. Callsnapshot()again.
- Selector fields
- Element fields
- Common options
- ui_element examples
- List text elements (ui_element.list_text_elements)
- Get UI element at position (ui_element.text_element_at_position)
- Find one UI element (ui_element.find)
- Find multiple UI elements (ui_element.find_all)
- Capture a UI snapshot (ui_element.snapshot)
- Click a UI element (ui_element.click)
- Scroll a UI element or current page (ui_element.scroll)
- Append text input (ui_element.input_text)
- Set text content (ui_element.set_text)
- Clear text content (ui_element.clear_text)
- Toggle control state (ui_element.toggle)
- Set checked state (ui_element.set_checked)
- Set control value (ui_element.set_value)
- Increase control value (ui_element.increase)
- Decrease control value (ui_element.decrease)