在Androidviewclient中实现无限滚动

Implement infinite scrolling in Androidviewclient

我正在尝试为实现列表项滚动的应用程序实现 Androidviewclient 5.1.1。我想滚动到列表的所有条目都已完成的位置。 即可滚动变为 FALSE。

我应该如何进行此操作?
我应该检查哪个 属性 或 ANDROIDVIEWCLIENT?

我使用 culebra GUI (from AndroidViewClient 9.2.1) 生成此脚本 scrollable.py,而 运行 设备上的 联系人 应用程序。

culebra -pVCLGo scrollable.py

为了滚动列表,我使用了 culebra: the magical drag 中描述的拖动对话框。

退出 GUI 并生成脚本后,我删除了除 ListView 之外的所有其他视图并添加了 while 循环。因此,除了 while 循环之外,几乎所有内容都是自动生成的。

最终脚本现在是:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2014  Diego Torres Milano
Created on 2015-01-21 by Culebra v9.2.1
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''


import re
import sys
import os


try:
    sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.viewclient import ViewClient

TAG = 'CULEBRA'

_s = 5
_v = '--verbose' in sys.argv


kwargs1 = {'ignoreversioncheck': False, 'verbose': True, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True}
vc = ViewClient(device, serialno, **kwargs2)

device.Log.d(TAG, "dumping content of window=-1",  _v)
vc.dump(window=-1)

def doSomething(view):
    if view.getClass() == 'android.widget.TextView':
        print view.getText()

while True:
    device.Log.d(TAG, "finding view with id=android:id/list",  _v)
    android___id_list = vc.findViewByIdOrRaise("android:id/list")
    # check if scrollable
    if not android___id_list.isScrollable():
        break
    vc.traverse(root=android___id_list, transform=doSomething)
    device.Log.d(TAG, "Scrolling",  _v)
    device.dragDip((185.0, 499.0), (191.0, 175.5), 200, 20, 0)
    vc.sleep(1)
    device.Log.d(TAG, "dumping content of window=-1",  _v)
    vc.dump(window=-1)

NOTE: in this case, the script never exits because the ListView in Contacts never changes its scrollable property, which I hope your app does as you mentioned in your question.

编辑 1

根据其中一条评论的要求,为 ListView 子级添加了树遍历

编辑 2

添加了 doSomething() 转换方法

编辑 3

现在检查 class