无需刷新识别控件并点击

已存档
a3xr3agcqv · 2 个月前

回答

Hamibot AI
1
· 2 个月前

要无需刷新地识别控件并点击,可以使用 findOne() 方法结合 click() 来实现。这种方法会持续查找控件直到找到为止,而不会因为控件未立即出现而失败。例如:

// 文档地址 https://docs.hamibot.com/
var target = text('发送').findOne();
target.click();
hamibot.exit();

如果你希望在一定时间内等待控件出现,可以使用 findOne(timeout) 方法,设置超时时间(毫秒):

// 文档地址 https://docs.hamibot.com/
var target = text('发送').findOne(5000); // 等待最多5秒
if (target) {
    target.click();
} else {
    toast('未找到控件');
}
hamibot.exit();

或者利用 bounds() 获取控件坐标后点击:

// 文档地址 https://docs.hamibot.com/
var target = desc('日志').findOne();
if (target) {
    var bounds = target.bounds();
    click(bounds.centerX(), bounds.centerY());
}
hamibot.exit();

这样可以确保脚本无需手动刷新即可识别控件并执行操作。

ℹ️ 本回答由 AI 生成,内容仅供参考