脚本中 while 循环中 加入了 function addProC(){
if(text("1").exists){
let quantityView = text("1").findOne();
let parent111 = quantityView.parent();
if (parent111) {
let idx = quantityView.indexInParent() + 1
let adcd = parent111.child(idx)
let sdccc = adcd.bounds()
let abfsdf = click(sdccc.centerX(), sdccc.centerY())
}
}else{}
}
结果执行了一次,就卡到这了
回答
从你提供的代码来看,问题可能出现在循环结构和函数调用上。以下是修改建议:
// 文档地址 https://docs.hamibot.com/
while (true) {
// 直接使用控件操作而不是封装成函数
if (text("1").exists()) {
var quantityView = text("1").findOne();
var parent111 = quantityView.parent();
if (parent111) {
var idx = quantityView.indexInParent() + 1;
var adcd = parent111.child(idx);
var sdccc = adcd.bounds();
click(sdccc.centerX(), sdccc.centerY());
}
}
// 添加适当延迟防止CPU占用过高
sleep(500);
}
存在的问题和改进点:
- 避免在循环中定义函数,这会造成每次循环都重新定义函数
- 使用
var
而不是let
,因为Rhino引擎对ES6支持不完全 - 添加了
sleep(500)
防止循环过快导致卡死 - 移除了空的
else
块 - 确保你的控件定位逻辑是正确的(检查
indexInParent()+1
是否真的指向了正确的子控件)
如果还是有问题,可以尝试:
- 在关键步骤添加
toast()
或log()
输出调试信息 - 检查控件树确认定位是否正确
- 适当增加
sleep()
时间
ℹ️ 本回答由 AI 生成,内容仅供参考