使用adb命令获取设备UI(hierarchy)信息

安卓设备版本在4.0以上,而且打开了View Server(这不一定根据手机,有的手机不需要打开就能通过Hierarchy Viewer可以看到app的UI结构),如果不能看到,执行打开命令:

adb shell service call window 1 i32 4939 
然后通过执行如下命令判断是否开启View Server: 
adb shell service call window 3 
若返回值是:Result: Parcel(00000000 00000001 '........') 说明View Server处于开启状态 
若返回值是:Result: Parcel(00000000 00000000 '........') 说明View Server处于关闭状态 
如果想关闭View Server执行如下命令: 
adb shell service call window 2 i32 4939

如果能成功通过uiautomator查看app的页面元素,说明你可以进行如下命令:

adb shell uiautomator dump --compressed  /data/local/tmp/uidump.xml
这个命令是把设备UI信息存入在设备文件uidump.xml

/data/local/tmp/uidump.xml

通过命令,把设备上的命令拉取到PC桌面上,下面是问我执行的命令实例:

adb pull "/data/local/tmp/uidump.xml "    "C:\Users\e.wang\Desktop"


获取的设备UI信息文件uidump.xml中的信息内容如下:

   
- 
- 
- 
- 
   
  
- 
   
  
- 
   
  
- 
   
  
- 
   
  
- 
   
  
- 
   
  
- 
   
  
- 
   
  
- 
   
  
- 
   
  
- 
   
  
- 
   
  
- 
   
  
  
- 
   
   
  
- 
   
   
   
   
  
  
  

你可能感兴趣的:(ADB命令使用手册)