Python获取uiautomator文件保存在电脑的脚本

import time
import os
uix_name=str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()))
#用时间戳生成名字
os.system('adb devices') #获取连接设备

dump_uix='adb shell uiautomator dump /sdcard/uix/'+uix_name+'.uix'
#通过时间戳对uix和图片进行命名并截取保存在手机下
dump_png='adb shell screencap -p /sdcard/uix/'+uix_name+'.png'
pull_uix='adb pull /sdcard/uix/'+uix_name+".uix E:\\APPUI"
pull_png='adb pull /sdcard/uix/'+uix_name+".png E:\\APPUI"

result=os.system(dump_uix)
if result:
    print('无uix')
else:
    print('有uix')
    os.system(pull_uix)
    os.system(dump_png)
    os.system(pull_png)
print(dump_uix,dump_png,pull_uix,pull_png)

 

保存下来的使用方法:

1、打开 uiautomatorviewer路径在 SDK的tools件夹中 这个是我的路径(C:\Program Files (x86)\Android\android-sdk\tools)

 Python获取uiautomator文件保存在电脑的脚本

2、 点击打开文件,选择保存在电脑的文件(注意文件和图片要对应)

Python获取uiautomator文件保存在电脑的脚本

 然后就可以查看对应 元素进行操作了