E不小心

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

有些手机可以通过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,是没有那个按钮的信息,回头再尝试一下其它方法

posted on 2021-09-23 12:15  E不小心  阅读(296)  评论(0编辑  收藏  举报