Unexpected error while obtaining UI hierarchy java.lang.reflect.InvocationTargetException
文章来源:https://blog.csdn.net/dengachao/article/details/100535536
错误信息:
android8以后sdk自带的uiautomator直接打开,截取不到机器界面信息
解决方法:
一.获取uix文件
步骤:
1.adb shell uiautomator dump /sdcard/sc.uix (/sdcard/ 为手机存储目录)
2.adb pull /sdcard/sc.uix
解析:
adb shell uiautomator dump dump出当前窗口UI布局信息
adb pull 从手机上传文件到电脑 (默认保存在当前电脑的用户工作目录下,c:\users\xxx,adb pull的语法 adb pull remote local)
remote 远程目录步骤1保存sc.uix的路径
local 当前pc的路径,不写,即默认
二.截取屏幕
1.将手机的app切换到响应页面
2.在电脑执行如下命令截取屏幕
adb shell screencap -p /sdcard/sc.png (截屏)
adb pull /sdcard/sc.png
解析:
adb shell screencap -p 截屏并保存成png 保存到手机端
三.截图与资源
1.打开uiautomator工具
2.点击左上角的文件夹
3.导入截图
4.导入ui资源
通过以上步骤,即可正常定位元素了