代码没啥难度就是一步一步的找元素,最后点击清理按钮。
auto.waitFor(); app.launchApp('今日头条极速版'); sleep(10000); console.show(); //开启日志(悬浮窗权限) clearMyCache(); back();//返回我的页面 sleep(1000); home();//关闭当前程序 /** * 清理缓存 */ function clearMyCache() { if (className("android.widget.TextView").text("我的").exists()) { let b = className("android.widget.TextView").text("我的").findOnce().bounds(); let clickResult = click(b.centerX(), b.centerY()); sleep(3000); if (clickResult) { swipe(350, 1400, 350, 150, 300); sleep(5000); if (className("android.widget.TextView").text("系统设置").exists()) { toastLog("Click系统设置"); let b = className("android.widget.TextView").text("系统设置").findOnce().bounds(); click(b.centerX(), b.centerY()); } sleep(3000); if (className("android.widget.TextView").text("清除缓存").exists()) { let b = className("android.widget.TextView").text("清除缓存").findOnce().bounds(); click(b.centerX(), b.centerY()); } sleep(3000); if (className("android.widget.Button").text("确定").exists()) { let b = className("android.widget.Button").text("确定").findOnce().bounds(); let result=click(b.centerX(), b.centerY()); if(result){ toastLog("清理成功"); } sleep(3000); } } else { toastLog("点击我的失败"); } } } /** *点击一下屏幕 */ function clickScreen() { var x = device.width - device.width * 0.2; var y = device.height - device.height * 0.2; toastLog("点击屏幕" + x + ":" + y); let clickResult = click(x, y); toastLog(clickResult); }