android.widget.ListView/Python/uiautomator script
阿新 • • 發佈:2018-12-12
Get GUI through
android-sdk-linux/tools/bin/uiautomatorviewer
Python script to automatic click to downlowd all item in android.widget.ListView
def percent_to_int(string): if "%" in string: newint = int(string.strip("%")) return newint else: return int(0) def download_listview_oneitem(): ##print('Stop all') ###d(resourceId="com.XXXXX:id/tv_stopAll").click() download_list=d(resourceId="com.XXXX:id/lv_download") print(download_list.info) currentIndex = 0 ; if d(resourceId="com.XXXXX:id/lv_download").child(index=currentIndex).exists : download_list=d(resourceId="com.XXXXX:id/lv_download") first=d(resourceId="com.XXXXX:id/lv_download").child(index=currentIndex) #print(first.info) number=first.child(resourceId="com.XXXXX:id/down_number") title=first.child(resourceId="com.XXXXX:id/down_title").text print(title+ " percent now is "+number.text) number_int=percent_to_int(number.text); if number_int<100 : if first.child(text='已經暫停',resourceId="com.XXXXX:id/down_status").exists : print("Download now :"+title) first.click() d.watcher("Auto_Close_Download_Error").when(text="錯誤").click(text="確定"); d.watchers.run() time.sleep(1) #first.child(resourceId="com.XXXXX:id/down_progress").wait.gone(timeout=60000) first.child(text='正在快取',resourceId="com.XXXXX:id/down_status").wait.gone(timeout=60000) else : print("Wait for :"+title) else : ### !!! Error item if first.child(text='正在快取',resourceId="com.XXXXX:id/down_status").exists : print("!!! Error, exceed 100, Stop Download now! " + title) first.click() return else : print("!!! A dead item , skip this, Error, exceed 100 " + title) return print('Done!') try: while (1) : download_huaqing_oneitem() except Exception, e: print u"Download fails\n", e