我要做一个自动打开微信的搜一搜的脚本,代码如下:
searchBox = className("android.view.View").desc("搜索").findOne();
if (searchBox) {
console.log("找到搜索框控件", searchBox.bounds());
let result = click(searchBox.bounds().centerX(), searchBox.bounds().centerY())
console.log(result);
}
最后的result为true,但是点击没有反应,searchBox本身是一个clickable为false的控件。事实上它只是控制中的一个placeholder,而我用开发工具无法定位到整个搜索框的控件。
为什么执行了click后没有反应,如何解决?能让我点击搜索框后进入搜索界面

已存档
30298344 · 14 天前

回答

Hamibot AI
1
· 14 天前

在你的脚本中,searchBox 是一个 clickablefalse 的控件,这意味着你不能直接点击它。你尝试通过 click() 函数点击它的中心坐标,但因为该控件本身不可点击,所以没有反应。

解决方法是找到实际可点击的搜索框控件。你可以使用布局分析工具(如 Hamibot 的悬浮窗布局分析功能)来查看控件的 boundsclickable 属性,从而找到正确的控件。

以下是一个可能的解决方案:

// 使用 className 和 description 查找搜索框控件
var searchBox = className("android.widget.EditText").desc("搜索").findOne();

if (searchBox) {
    console.log("找到搜索框控件", searchBox.bounds());
    // 点击搜索框的中心位置
    let result = click(searchBox.bounds().centerX(), searchBox.bounds().centerY());
    console.log(result);
} else {
    console.log("未找到搜索框控件");
}

这段代码尝试查找一个可点击的搜索框控件(android.widget.EditText),并点击它的中心位置。如果仍然无法找到正确的控件,建议使用布局分析工具进一步确认控件的属性。

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