Chuyển tới nội dung chính

Chụp trạng thái giao diện (ui_element.snapshot)

Hàm này khả dụng trong các phiên bản sau 20260507

Khai báo

snapshot, err = ui_element.snapshot([ options ])

Tham số

Giá trị trả về

  • snapshot Bảng. Danh sách phần tử giao diện hiện tại kèm các phương thức ảnh chụp trạng thái. nil khi thất bại.
  • err Chuỗi. Lý do thất bại.

Phương thức ảnh chụp trạng thái

element = snapshot:find(selector)
elements = snapshot:find_all(selector)
ok, info = snapshot:click(selector_or_element [, options ])
ok, info = snapshot:scroll([ selector_or_element, ] direction [, options ])
ok, info = snapshot:input_text(selector_or_element, text [, options ])
ok, info = snapshot:set_text(selector_or_element, text [, options ])
ok, info = snapshot:clear_text(selector_or_element [, options ])
ok, info = snapshot:toggle(selector_or_element [, options ])
ok, info = snapshot:set_checked(selector_or_element, checked [, options ])
ok, info = snapshot:set_value(selector_or_element, value [, options ])
ok, info = snapshot:increase(selector_or_element [, options ])
ok, info = snapshot:decrease(selector_or_element [, options ])

Mô tả

Ảnh chụp trạng thái là kết quả tại một thời điểm, hữu ích cho việc tra cứu lặp lại hoặc thực hiện liên tiếp các thao tác trên cùng màn hình. Sau khi điều hướng, hiển thị cửa sổ bật lên, cuộn hoặc làm mới nội dung, hãy gọi lại snapshot(). Các trường ảnh chụp trạng thái thường gặp gồm elementscount.

Ví dụ

local ui_element = require("ui_element")

local ui, err = ui_element.snapshot({
max_level = 2,
})

if ui then
local search = ui:find({
title = "Tìm kiếm",
role = "text_field",
})
if search then
ui:set_text(search, "XXTouch")
end
else
sys.toast(err)
end

Lưu ý: Ví dụ dùng API ngoài chương này là sys.toast.