uiautomator 在我的 python 脚本中无限卡住[已关闭]

问题描述 投票:0回答:1

我运行以下代码以在 Android 设备上显示文本:

from uiautomator import Device

def capture_text():
    d = Device()
    current_text = d.info
    print(f'current text: {current_text}')

capture_text()

我运行它,它永远卡住了,

我是否犯了任何错误或者我应该修复此代码?

python android python-3.x ui-automation android-uiautomator
1个回答
0
投票

你可以这样尝试

from uiautomator import Device

def capture_text():
    d = Device()
    element = d(resourceId='your_element_id')
    if element.exists and element.visible:
        text = element.text
        print(f'Captured text: {text}')
    else:
        print('Element not found or not visible')

capture_text()
© www.soinside.com 2019 - 2024. All rights reserved.