Android app 元素定位除了使用Appium Inspector 外,還可以使用Android SDK 里tools中的uiautomatorviewer 工具。但今天打算使用 uiautomatorviewer 進(jìn)行元素定位的時(shí)候,發(fā)現(xiàn)無法截圖,并報(bào)如下錯(cuò)誤:
Unexpected error while obtaining UI hierarchy
# 點(diǎn)擊Details
java.lang.reflect.InvocationTargetException

查找資料了解到,從Android 8.0開始,SDK 工具軟件包在新版本中已經(jīng)棄用,所以tools里的uiautomatorviewer工具都不支持了。于是開始查找解決方法。
1,使用adb命令截圖,再導(dǎo)入uiautomatorviewer進(jìn)行定位。這種方法雖然可行,但太麻煩了。
2,下載修改過的 uiautomatorviewer.bat,將tools里的uiautomatorviewer.bat文件替換掉。但在某博客網(wǎng)站上居然需要money才能下載,表示譴責(zé)......

3,終極方法?。。?!將SDK目錄中tools文件夾下lib中的ddmlib、ddms、ddmuilib 、uiautomatorviewer這四個(gè)jar文件替換掉即可。下面是這四個(gè)新文件的下載地址:
鏈接:https://pan.baidu.com/s/1NIPNk8ApQIPveVkAfVOpJA
提取碼:k5rc
替換完成后,重新打開tools中uiautomatorviewer.bat即可進(jìn)行元素定位。