首页 > 解决方案 > AndroidViewClient:如何知道我们将屏幕完全拖到最后

问题描述

我想使用 ID 向所有朋友发送消息,我的屏幕一次只显示 12 个 ID。在这里,我正在收集列表中的所有 ID 并向所有 12 个 ID 发送消息,现在我清除了 ID 列表并拖动屏幕。现在拿起新的身份证。所以,我想知道我已经完全拖动屏幕直到我可以终止外循环。

name = list(vc.findViewsWithAttribute('class','javaClass'))
while True:
    for i in range(len(name)):
        try:
            vc.dump()
            name[i].touch()
            vc.dump()
            vc.findViewWithText('Chat').touch()
            new_message = message 
            vc.dump()
            message_field = vc.findViewByIdOrRaise("com.snapchat.android:id/chat_input_text_field")
            message_field.setText(new_message)
            time.sleep(1)
            vc.dump()
            d.press("input keyevent KEYCODE_ENTER")
            vc.dump()
            vc.findViewByIdOrRaise("com.snapchat.android:id/back_button").touch()
        except:pass
    try:
        name.clear()
        device.drag((200, 500), (200,180), 68, 20, 0)
        name = list(vc.findViewsWithAttribute('class','javaClass'))
    except: pass

我想更改while True:条件,因为它是一个无限循环。

标签: androidpython-3.xandroidviewclient

解决方案


我认为这样的事情应该有效

last_name = None
name = list(vc.findViewsWithAttribute('class','javaClass'))
while last_name != name[-1]:
    for i in range(len(name)):
        try:
            vc.dump()
            name[i].touch()
            vc.dump()
            vc.findViewWithText('Chat').touch()
            new_message = message 
            vc.dump()
            message_field = vc.findViewByIdOrRaise("com.snapchat.android:id/chat_input_text_field")
            message_field.setText(new_message)
            time.sleep(1)
            vc.dump()
            d.press("input keyevent KEYCODE_ENTER")
            vc.dump()
            vc.findViewByIdOrRaise("com.snapchat.android:id/back_button").touch()
        except:pass
    try:
        name.clear()
        device.drag((200, 500), (200,180), 68, 20, 0)
        last_name = name[-1]
        name = list(vc.findViewsWithAttribute('class','javaClass'))
    except: pass


推荐阅读