adb shell
控制台是否可以使用其 id 访问 Android 应用程序的特定按钮?还是文字?
我正在尝试使设备上的按钮点击自动化。这是一个从浏览器访问的网络应用程序。那么,如果我有那个按钮 ID,我可以向那个按钮发送一个 Action 吗?
最佳答案
UI 自动化器提供资源 ID、文本和 UI 元素的边界。可以使用 XML 查看器或 Chrome 浏览器来更好地查看文件。
adb pull $(adb shell uiautomator dump | grep -oP '[^ ]+.xml') /tmp/view.xml
可以提取 UI 元素的边界并计算中点。根据需要将 text=
替换为 resource-id=
或 content-desc=
。
coords=$(perl -ne 'printf "%d %d\n", ($1+$3)/2, ($2+$4)/2 if /text="MY_BUTTON_TEXT"[^>]*bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"/' /tmp/view.xml)
现在我们在 $coords
中有了 UI 元素中心的坐标,我们只需要发送一个点击事件。
adb shell input tap $coords
关于android - 使用 ADB 访问屏幕上的特定 UI 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18924968/