当屏幕上未显示某些内容时,如何使用pythons UIAutomator获取列表框的所有项目

时间:2018-11-08 16:24:21

标签: python uiautomator

如何使用Python和UIAutomator

  1. 计算整个页面上给定项目的数量(不仅仅显示)
  2. 循环浏览它们以检查信息。

就我而言,我有一个包含一些数据的呼叫列表,我想测试显示的呼叫数量是否正确,并在列表中搜索特定的数字。 以下摘录是我要验证计数(以确保计数不超过100)然后搜索特殊调用的重复节点。

    <node index="4" text="" resource-id="com.myd.dialer:id/fragment_recent_list_view" class="android.widget.ListView" package="com.myd.dialer" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="true" scrollable="true" long-clickable="false" password="false" selected="false" bounds="[11,193][789,1145]">
      <node index="0" text="" resource-id="" class="android.widget.RelativeLayout" package="com.myd.dialer" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[11,193][789,301]">
        <node index="0" text="1002" resource-id="com.myd.dialer:id/list_item_recent_text_view_name" class="android.widget.TextView" package="com.myd.dialer" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[86,204][432,247]" />
        <node index="1" text="11/07 08:40" resource-id="com.myd.dialer:id/list_item_recent_text_view_date" class="android.widget.TextView" package="com.myd.dialer" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[432,204][778,247]" />
        <node index="2" text="00:00:00" resource-id="com.myd.dialer:id/list_item_recent_text_view_duration" class="android.widget.TextView" package="com.myd.dialer" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[184,247][778,290]" />
      </node>
      <node index="1" text="" resource-id="" class="android.widget.RelativeLayout" package="com.myd.dialer" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[11,302][789,410]">
        <node index="0" text="1004" resource-id="com.myd.dialer:id/list_item_recent_text_view_name" class="android.widget.TextView" package="com.myd.dialer" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[86,313][432,356]" />
        <node index="1" text="11/07 08:40" resource-id="com.myd.dialer:id/list_item_recent_text_view_date" class="android.widget.TextView" package="com.myd.dialer" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[432,313][778,356]" />
        <node index="2" text="00:00:00" resource-id="com.myd.dialer:id/list_item_recent_text_view_duration" class="android.widget.TextView" package="com.myd.dialer" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[184,356][778,399]" />
      </node>
      ...
    </node>



我可以做到:

listViewObj = dev(resourceIdMatches="com.myd.dialer:id/fragment_recent_list_view")
listViewObj.fling.toEnd()  #will scroll to end of list
print("listViewObj count = ".format(str(listViewObj.count)))    # this is 0?
# get name objects
objs = dev(resourceIdMatches="com.myd.dialer:id/list_item_recent_text_view_name")
cnt = objs.count      # giving 9 not 99 or 100 etc (9 can show on the screen)
print("obs count = {}".format(str(cnt)))
for o in objs:
    print("{}".format(o.info['text']))  # will print text item

但这只会让我只对屏幕上的那些项目进行计数(并打印)。
如何获得整个列表的访问权限?

谢谢!

0 个答案:

没有答案