uiautomator2+python获取当前页面的activity

def get_current_activity():
    """
    获取当前页面的activity
    :return:
    """
    cmd = 'adb -s {} shell "dumpsys window | grep mCurrentFocus"'.format(
        get_android_devices())
    activity_info = invoke(cmd).splitlines()
    log.info(activity_info)
    activity = str(activity_info[-1]).split("/")[-1][:-1]
    log.info(activity)
    return activity

adb shell "dumpsys window | grep mCurrentFocus
可以执行命令查看
 

华为P30

 

vivox50

 

因此上方的获取activity需要使用[-1]

 

posted @ 2023-06-16 14:48  陈文芝  阅读(475)  评论(0编辑  收藏  举报