脚本引擎 API
节点操作 API
runtime.nodes.* 基于无障碍节点树的可达节点操作。支持点击、输入、清空、双击、滑动、存在性检查与层级导出。
概述
基于无障碍节点树进行操作。节点选择器 selector 是一个 JS 对象,支持 className/packageName/text/viewId/desc 字段的精确或包含匹配。
选择器格式
selector 对象的字段均为可选:
- className: string — 节点类名,如 'android.widget.Button'。
- text: string — 节点文字内容。
- viewId: string — 节点的资源 ID。
- desc: string — 节点内容描述。
- packageName: string — 所属应用包名。
方法列表
runtime.nodes.click(selector): void— 点击匹配节点。runtime.nodes.exists(selector): boolean— 节点是否存在。runtime.nodes.input(selector, text): void— 在匹配输入框中输入文字。runtime.nodes.clearInput(selector): void— 清空输入框内容。runtime.nodes.doubleClick(selector, intervalMs?: 80): void— 双击节点,intervalMs 为点击间隔。runtime.nodes.swipe(selector, direction, distanceRatio?: 0.5, durationMs?: 300): void— 在匹配节点上滑动。direction 为 UP/DOWN/LEFT/RIGHT。runtime.nodes.dumpHierarchy(): string— 导出当前无障碍节点层级结构(调试用)。
调用示例
// 按文字查找并点击
runtime.nodes.click({text: "确定"});
// 按类名查找输入框并输入
runtime.nodes.input({className: "EditText"}, "hello");
// 检查节点是否存在
var exists = runtime.nodes.exists({text: "加载中"});
if (exists) { runtime.process.log("正在加载"); }// 节点滑动
runtime.nodes.swipe({className: "RecyclerView"}, "DOWN", 0.3, 200);
// 双击节点
runtime.nodes.doubleClick({text: "播放"}, 100);
// 导出层级用于调试
var hierarchy = runtime.nodes.dumpHierarchy();
runtime.files.write("/sdcard/hierarchy.xml", hierarchy);