0

I am trying to implement Androidviewclient 5.1.1 for app which has implement scrolling of listitems. I want to scroll upto the point all the entries of the list have been finished. That is scrollable becomes FALSE.

How should I proceed to do this ?
Which property or ANDROIDVIEWCLIENT should I check for?

1 Answers1

1

I used culebra GUI (from AndroidViewClient 9.2.1) to generate this script scrollable.py while running the Contacts app on the device.

culebra -pVCLGo scrollable.py

To scroll the list I used the drag dialog as described in culebra: the magical drag.

Once I exited the GUI and the script was generated, I remove all the other Views but the ListView and added the while loop. So besides the while loop, pretty much everything was automatically generated.

The final script is now:

#! /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.

EDIT 1

Added tree traversal for ListView children as requested in one of the comments

EDIT 2

Added doSomething() transform method

EDIT 3

Now check the class

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • But how did you get the value of each item in the list view? – Kshitij Sharma Jan 21 '15 at 14:34
  • After `vc.dump(window=-1)` you'll have the visible items. So you can use `vc.findView*()`. Furthermore, the return value of `vc.dump()` is the list of Views, so you can also iterate over it. – Diego Torres Milano Jan 21 '15 at 15:24
  • But my first question is: do you detect the end (scrollable == False)? – Diego Torres Milano Jan 21 '15 at 15:25
  • I am trying to detect but doesnt seem to find. Tell me one thing , there are multiple text views in the lists , but all of them have the same id , for eg. there are 10 contacts and each of them has the same id, then how to iterate over them until I fetch all values? – Kshitij Sharma Jan 21 '15 at 15:52
  • Iterate over all the children of the ListView – Diego Torres Milano Jan 21 '15 at 15:54
  • How to do that ? And i constantly get this error ERROR: UiAutomator output contains no valid information. UiAutomator was killed, no reason given. How to resolve this ? – Kshitij Sharma Jan 21 '15 at 16:59
  • You have added listview traversal, but how to fetch the textview from each list item during its traversal ? – Kshitij Sharma Jan 21 '15 at 17:07
  • Instead of using TRAVERSE_CIT create another method that receives a View as parameter and do whatever you want with it. Check `viewclient.py` to see how the method are implemented, after all this is why it's Open Source ;-) – Diego Torres Milano Jan 21 '15 at 17:28
  • But what is TRAVERSE_CIT ? and what view are you talking about here ? – Kshitij Sharma Jan 21 '15 at 17:44
  • So it should be like this ? while True: 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=android_textview.Traverse_CIT) vc.sleep(1) vc.dump(window=-1) I am not getting it , could you please help me get text out of each lisitem , the listitem contains text container names as android_row_textview . – Kshitij Sharma Jan 21 '15 at 18:09
  • I see doSomething() method , but could you provide sample to extract textview from the listview please ?http://stackoverflow.com/questions/28074399/parsing-listview-in-androidviewclient – Kshitij Sharma Jan 21 '15 at 18:44
  • But you havent passed anything in doSomething in the command transform=doSomething . Is that ok ? – Kshitij Sharma Jan 21 '15 at 19:16
  • That **IS** precisely the point, passing the function/method pointer. – Diego Torres Milano Jan 21 '15 at 19:17
  • so write now what i am getting is all textviews in the view , but Like my textview (which i want to get )is named com__android___id_row_user_username = vc.findViewByIdOrRaise("com.uphere.android:id/row_user_username") , so if i want to get only these ids , how can i do it ? – Kshitij Sharma Jan 21 '15 at 19:20
  • I don't get it. Update your question and be more specific, add a subtree example, use print in doSomething() to print something, etc. – Diego Torres Milano Jan 21 '15 at 19:30
  • It worked for me ! Thanks for the immense support ! :) – Kshitij Sharma Jan 21 '15 at 19:42
  • No problem. Enjoy AVC. – Diego Torres Milano Jan 21 '15 at 19:43
  • Just one thing more , after printing those textview "texts" on screen and scrolling down , after twice or third scroll I am getting this error : RuntimeError: ERROR: UiAutomator output contains no valid information. UiAutomator was killed, no reason given. – Kshitij Sharma Jan 21 '15 at 19:48
  • Shouldn't happen. Perhaps you need some sleep() – Diego Torres Milano Jan 21 '15 at 21:10