一万年来谁著史,三千里外欲封侯。这篇文章主要讲述使用uiautomatorviewer定位App元素相关的知识,希望能为你提供帮助。
这个工具是android SDK自带的,
日常的工作中经常要使用的,
在C:\\Android\\sdk\\tools\\bin目录下:

文章图片
双击之,
请注意,
我一般选择第一个机器人小图标Device Screenshot,
而不是第二个Device Screenshot with Compressed Hierarchy,
因为第二个是具有压缩层次结构的设备截图,
有可能不准确;

文章图片
首次启动会报错:
Unable to connect to adb. Check if adb is installed correctly.

文章图片
怎么解决呢?
关闭之,
打开uiautomatorviewer.bat文件,
【使用uiautomatorviewer定位App元素】修改最后一行:
%prog_dir%

文章图片
改为:
C:\\Android\\sdk\\platform-tools
并保存

文章图片
再次打开uiautomatorviewer:

文章图片
对应关系:
text find_element_by_android_uiautomator("new UiSelector().text(\\"文字\\")")
resource-id find_element_by_id
class find_element_by_class_name
content-desc find_element_by_accessibility_id
推荐阅读
- 关于Android
- Android沉浸式状态栏
- Android studio导入项目时的问题(Re-download dependencies and sync project (requires network))
- Android根据URL下载文件保存到SD卡
- Android中Activity被系统会收前页面信息保存
- Android资源文件命名与使用
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)D. Peculiar apple-tree
- Android Studio怎样创建App项目
- Android手机的USB转串口开发硬件以及软件源代码