今天遇到使用sdk中的uiautomatorviewer獲取手機元素時,居然提示Error obtaining UI hierarchy,最后解決方案是,把下面的代碼放到bat腳本中,運行一次就可以了:
call adb shell uiautomator dumpcall
call adb pull /storage/sdcard/window_dump.xml .
call window_dump.xml
如果還不行,用這種方式肯定可以:
- 新建一個bat文件,內容如下:
@echo on
adb shell uiautomator dump /sdcard/app.uix
adb pull /sdcard/app.uix E:/app.uix
adb shell screencap -p /sdcard/app.png
adb pull /sdcard/app.png E:/app.png
- 點擊這個bat文件
-
打開uiautomator.bat ,將文件加載進來
image.png - 但是這樣有個缺點,這個不是實時的,所以到不同也沒后,每次都要點下bat文件,然后用uiautomator去打開