使用uiautomatorviewer工具遇到以下問題-Unexpected error while obtaining UI hierarchy


手機型號:榮耀V9 安卓9
使用adb工具自帶的uiautomatorviewer.bat,打開后連接手機,報錯如下:
據說是因為uiautomatorview 不兼容安卓8.0以上版本

解決方法:
新建一個uiauto.bat文件,代碼如下:

adb shell uiautomator dump /sdcard/app.uix
#會在 D:\software\appium下生成app.uix,地址可根據自己的需求進行更改
adb pull /sdcard/app.uix D:\software\appium\app.uix
adb shell screencap -p /sdcard/app.png
#會在 D:\software\appium下生成app.png,地址可根據自己的需求進行更改
adb pull /sdcard/app.png D:\software\appium\app.png

雙擊運行uiauto.bat文件
打開uiautomatorviewer.bat,導入生成的app.uix和app.png文件,點擊OK即可

原理可以理解成“截屏”:先將手機當前頁面給“截屏”生成app.png,並且生成相對應的ui解析文件app.uix,將兩個同時導入uiautomatorviewer就可以定位手機頁面元素,不方便的是手機頁面發生變化就要重新“截屏”一次,所以寫成bat文件方便執行


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM