小知識分享:adb uiautomator 命令 dump ui 樹信息
之前給大家分享過一篇文章,講述如何通過 getevent/sendevent/input 命令向 android 手機(jī)設(shè)備接收和發(fā)送操作事件,來解決自動化腳本場景的需求。
其實(shí)還有一個(gè)小知識點(diǎn)需要補(bǔ)充一下,就是可以借助 uiautomator 命令 dump 當(dāng)前頁面的 ui hierarchy 信息。
一個(gè)完整的 uiautomator 命令類似:
adb shell uiautomator dump [--compressed] [file]
--compressed 參數(shù):輸出更加精簡的 layout 布局信息,包括 android:id/content 在內(nèi)的通用外層 ui 結(jié)構(gòu)都被拿掉了;
file 參數(shù):xml 格式輸出結(jié)果文件,默認(rèn)為 /sdcard/window_dump.xml;
還是老規(guī)矩,舉個(gè)簡單的例子。
~?yifeng$?adb?shell?uiautomator dump
UI hierchary dumped to: /sdcard/window_dump.xml
再通過 adb pull 命令將手機(jī) sdcard 里的文件傳輸?shù)诫娔X中。
adb?pull?/sdcard/window_dump.xml?Desktop/
用 Sublime 軟件打開,Indent XML 插件格式化后,就是這個(gè)樣子:
<hierarchy?rotation="0">
????<node?bounds="[0,0][1080,2340]"?checkable="false"?checked="false"?class="android.widget.FrameLayout"?clickable="false"?content-desc=""?enabled="true"?focusable="false"?focused="false"?index="0"?long-clickable="false"?package="com.feng.test"?password="false"?resource-id=""?scrollable="false"?selected="false"?text="">
????????<node?bounds="[48,128][341,208]"?checkable="false"?checked="false"?class="android.widget.TextView"?clickable="false"?content-desc=""?enabled="true"?focusable="false"?focused="false"?index="0"?long-clickable="false"?package="com.feng.test"?password="false"?resource-id=""?scrollable="false"?selected="false"?text="DemoApp"/>
????????<node?bounds="[339,1224][741,1368]"?checkable="false"?checked="false"?class="android.widget.Button"?clickable="true"?content-desc=""?enabled="true"?focusable="true"?focused="false"?index="1"?long-clickable="false"?package="com.feng.test"?password="false"?resource-id="com.feng.test:id/b_button"?scrollable="false"?selected="false"?text="HELLO?WORLD!"/>
????node>
hierarchy>
當(dāng)前頁面完整的 UI 樹結(jié)構(gòu)信息都 dump 出來了,包括 view 的類名、資源 ID 和屏幕位置坐標(biāo)等。
長按識別二維碼,即可關(guān)注我
評論
圖片
表情
