1 uiautomatorviewer简介
- 之前文章说明了
Appium Inspector
的定位使用方法; uiautomatorviewer
是另一种定位工具;uiautomatorviewer
是android-sdk
自带的元素定位工具;- 它是通过截屏分析
XML
布局文件方式,来提供控件信息的查看服务。
2 uiautomatorviewer特点
uiautomatorviewer
和Appium Inspector
有着明显的区别;Appium Inspector
功能相对比较强大;- 而
uiautomatorviewer
只能用于安卓系统; - 另外
uiautomatorviewer
只能用于元素定位,不支持通过该工具操作APP
,也不支持录制功能等。
3 uiautomatorviewer启用
uiautomatorviewer
位于SDK目录下的tools\
目录下;- 比如我的是:
D:\android-sdk-windows\tools
: - 双击
uiautomatorviewer.bat
进行启动即可:
4 Work Bar
-
Work Bar
即工作栏,工作栏中有4个按钮,如图所示: -
从左到右依次为:
图标 | 名称 | 说明 |
---|---|---|
1 |
Open |
打开已保存的布局 |
2 |
Device Screenshot(uiautomator dump) |
获取详细布局 |
3 |
Device Screenshot with Cpmpressed Hierarchy (uiautomator dump) |
获取简介布局 |
4 |
Save |
保存布局 |
- 其中
4
保存时将保存两个文件,一个是图片,一个是.uix
文件; - 可以查看图片显示:
- 也可以查看
XML
格式内容:
python
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<hierarchy rotation="0">
<node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
<node index="0" text="" resource-id="" class="android.widget.LinearLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
<node index="0" text="" resource-id="android:id/content" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
<node index="0" text="" resource-id="com.android.launcher3:id/launcher" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
<node index="0" text="" resource-id="com.android.launcher3:id/drag_layer" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
<node index="0" text="" resource-id="com.android.launcher3:id/workspace" class="com.android.launcher3.Workspace" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="true" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
<node index="1" text="" resource-id="" class="android.view.ViewGroup" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[8,184][760,976]">
<node index="0" text="" resource-id="" class="android.view.ViewGroup" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[8,184][760,976]">
<node index="0" text="QQi" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="QQi" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[8,184][196,382]" />
<node index="1" text="Settings" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Settings" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[384,778][572,976]" /></node>
<node index="1" text="" resource-id="" class="android.view.View" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[8,184][220,406]" /></node>
</node>
<node index="1" text="" resource-id="com.android.launcher3:id/search_drop_target_bar" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][768,184]">
<node index="0" text="" resource-id="" class="android.appwidget.AppWidgetHostView" package="com.android.launcher3" content-desc="Search" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][768,184]">
<node index="0" text="" resource-id="" class="android.widget.RelativeLayout" package="com.android.quicksearchbox" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][768,184]">
<node index="0" text="" resource-id="com.android.quicksearchbox:id/search_plate" class="android.widget.LinearLayout" package="com.android.quicksearchbox" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][768,184]">
<node NAF="true" index="0" text="" resource-id="com.android.quicksearchbox:id/search_icon" class="android.widget.ImageView" package="com.android.quicksearchbox" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[19,68][115,164]" />
<node NAF="true" index="1" text="" resource-id="com.android.quicksearchbox:id/search_widget_text" class="android.widget.TextView" package="com.android.quicksearchbox" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[115,79][740,153]" /></node>
</node>
</node>
</node>
<node index="3" text="" resource-id="com.android.launcher3:id/page_indicator" class="android.widget.LinearLayout" package="com.android.launcher3" content-desc="Home screen 2 of 2, Settings" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[360,992][408,1016]">
<node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[360,992][384,1016]">
<node index="1" text="" resource-id="com.android.launcher3:id/inactive" class="android.widget.ImageView" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[360,992][384,1016]" /></node>
<node index="1" text="" resource-id="" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[384,992][408,1016]">
<node index="0" text="" resource-id="com.android.launcher3:id/active" class="android.widget.ImageView" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[384,992][408,1016]" /></node>
</node>
<node index="4" text="" resource-id="com.android.launcher3:id/hotseat" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,1016][768,1184]">
<node index="0" text="" resource-id="com.android.launcher3:id/layout" class="android.view.ViewGroup" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[0,1016][768,1184]">
<node index="0" text="" resource-id="" class="android.view.View" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,1016][192,1184]" />
<node index="1" text="" resource-id="" class="android.view.ViewGroup" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,1016][768,1184]">
<node index="0" text="Phone" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Phone" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[29,1022][163,1178]" />
<node index="1" text="Contacts" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Contacts" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[173,1022][307,1178]" />
<node index="2" text="" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Apps" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[317,1022][451,1178]" />
<node index="3" text="Messaging" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Messaging" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[461,1022][595,1178]" />
<node index="4" text="Browser" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Browser" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[605,1022][739,1178]" /></node>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</hierarchy>
- 其中
2
会显示全部布局; - 其中
3
只显示部分有用的控件布局。
5 Screenshot
screenshot
是截图区域,在图中的左侧部分;- 主要是显示当前屏幕的布局图片:
6 控件布局
- 控件布局内容主要在右上方显示,以
XML
格式展示;
7 控件属性
- 控件属性显示在右下方,当点击一个控件时,将会在这显示其属性信息:
8 连接设备
- 直接点击工作栏中的第二个或第三个按钮即可连接到设备;
- 我们这里点击的是第二个按钮
Device Screenshot
;
9 Error while obtaining UI问题排查
- 当我们点击第二个按钮
Device Screenshot
时出现以下界面: - 这个说明报错了,没有连接上,那我们看下详细信息,点击【
Details
】:
python
Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!
- 大概意思是
Remote object doesn't exist
,就是说已经存在了一个连接,那我们就需要断开已经连接的才行; - 我们检查发现使用了
Appium-Inspector
已经连接了,我们点击【×
】断开这个会话连接:
- 重新再连接就可以使用
uiautomatorviewer
连接上了。