• 基于uiautomator2 安装 app,处理adb install 未知来源 风险管控的一个方式


    有些手机可以通过adb直接安装 app,但有些手机会提示风险提示,有的还要求输入密码等(oppo、vivo)

    正常基于uiautomator2 安装一个app

    import uiautomator2 as u2
    import os
    
    d = u2.connect()
    apk_path = os.path.normpath("./xxxx.apk")
    d.app_install(apk_path)
    

    有风险提示的一个方案

    现在是通过启动另一个线程,通过 uiautomator2 ,获取UI远程,然后输入点,只能点击位置,直接代码了。

    import adbutils
    import uiautomator2 as u2
    import os
    import threading
    
    
    def get_devices():
        # 获取设备
        return adbutils.adb.device_list()
    
    
    def install_app(d):
        apk_path = os.path.normpath("./xxxx.apk")
        d.app_install(apk_path)
    
    
    def click_install(d):
        if d(text="忘记密码").exists(timeout=30):
            d.send_keys("aA111111")
            d(text="安装").click()
    
        if d(text="继续安装").exists(timeout=10):
            d(text="继续安装").click()
            d(text="安装").click()
    
        if d(text="应用权限").exists():
            info = d.device_info
            x = info["display"]["width"] / 2
            y = info["display"]["height"]
            d.click(536, 2216)
    
    
    if __name__ == "__main__":
        devices = get_devices()
        print(devices)
        if devices is None or devices.__len__ == 0:
            print("not found devices")
    
        threads = []
    
        for device in devices:
            d = u2.connect(device.serial)
    
            th1 = threading.Thread(target=install_app, args=(d,))
            th2 = threading.Thread(target=click_install, args=(d,))
    
            th1.start()
            th2.start()
    
            th1.join()
            th2.join()
    
    
    

    PS: 但发现,有些系统是没办法找到继续安装的按钮的,查看ui hierarchy,是没有那个按钮的信息,回头再尝试一下其它方法

    本文原创手打,转载请注明出处。
  • 相关阅读:
    Scala学习笔记(四)—— 数组
    Scala学习笔记(三)—— 方法和函数
    Scala学习笔记(二)——Scala基础
    Scala学习笔记(一)
    HDFS和GFS对比学习
    HDFS原理学习
    c++日历问题
    Mapreduce学习
    c++动态规划解决数塔问题
    C++——数码管
  • 原文地址:https://www.cnblogs.com/gaoshang212/p/15323667.html
Copyright © 2020-2023  润新知