root开启adb,如果没连接会自动连接adb

import os
import win32api

import uiautomator2 as u2

from mouseToClick import MouseToClick
adb_path = 'C:\\Users\\yys53\\OneDrive\\scrcpy\\adb.exe'
ip_port = '192.168.31.109:5555'
# weixin_login

try:
    # 若报错可能没连接adb,背其他设置占用,因为多个模拟器使用adb会导致手机没连接,重新wifi连接adb
    d = u2.connect(ip_port)
except Exception as e:
    cmd = '%s kill-server %s ' % (adb_path, ip_port)
    os.system(cmd)

    cmd = '%s connect %s ' % (adb_path, ip_port)
    os.system(cmd)
    print(e)
    d = u2.connect(ip_port)


# d.unlock()

def adb(ml):
    text = os.popen("C:\\Users\\yys53\\OneDrive\\scrcpy\\adb.exe -s " + ip_port + " " + ml).read()
    return text



cmd = '%s shell settings put system screen_brightness 0 %s ' % (adb_path, ip_port)  # 调最暗
os.system(cmd)

for i in range(20):  # 找不到一直循环

    d.unlock()  # 解锁,
    d.app_start(package_name="com.tencent.mm")  # 启动应用,没有此行,有几率没有启动微信
    find = d.xpath('//*[@text="微信"]').wait(3)
    if find:
        find.click()
        try:
            win32api.ShellExecute(0, 'open', "C:\\Program Files (x86)\\Tencent\\WeChat\\WeChat.exe", '', '', 1)
        except Exception as result:
            print("未知错误 %s" % result)
        MouseToClick.find_picture(['weixin_login'])

        d.xpath('//*[@resource-id="com.tencent.mm:id/h2m"]').click()

        d.screen_off()  # 关闭屏幕
        cmd = '%s shell settings put system screen_brightness 120 %s ' % (adb_path, ip_port)  # 调120亮度
        os.system(cmd)

        break

 

二维码登录正在研究中,经常登录电脑微信,基本不会扫描,要手机确认就可以