How to use click_exists method in ATX

Best Python code snippet using ATX

芭芭农场.py

Source:芭芭农场.py Github

copy

Full Screen

...31 if exist_img('res/baba/task_taobao.png'):32 return33 d.app_stop('com.taobao.taobao')34 d.app_start('com.taobao.taobao')35 d(description="浮层关闭按钮").click_exists(timeout=1)36 d(text="芭芭农场").click(timeout=5)37 # if click_img('res/baba/red_package.png'):38 # d.press("back")39 # d(text="芭芭农场").click(timeout=2)40 d(description="浮层关闭按钮").click_exists(timeout=2)41 d(text="继续努力").click_exists(timeout=3)42 if not click_img('res/baba/ji_fei_liao.png'):43 return4445def start_taobao():46 d.app_stop('com.taobao.taobao')47 d.app_start('com.taobao.taobao')48 d(description="浮层关闭按钮").click_exists(timeout=1)49 d(text="芭芭农场").click(timeout=5)50 # if click_img('res/baba/red_package.png'):51 # d.press("back")52 # d(text="芭芭农场").click(timeout=2)53 d(description="浮层关闭按钮").click_exists(timeout=2)54 d(text="继续努力").click_exists(timeout=3)55 item = d(text="立即领取")56 if item:57 item.click()58 time.sleep(0.5)59 # 领取三个亲密度奖励60 d.click(0.209, 0.44)61 d.click(0.503, 0.434)62 d.click(0.807, 0.436)63 # 点击关闭64 d.click(0.907, 0.205)6566 #全部领取67 d.click(0.822, 0.69)68 d(text="关闭").click_exists(timeout=1)69 #点击兔子70 d.click(0.189, 0.684)71 #点击集肥料72 d.click(0.75, 0.898)73 #做任务74 taobao_task()75 #施肥76 fertilize()777879def get_bound():80 if d(text="亲密度"):81 d(text="亲密度").click()82 time.sleep(0.5)83 # 领取三个亲密度奖励84 d.click(0.209, 0.44)85 d.click(0.503, 0.434)86 d.click(0.807, 0.436)87 # 点击关闭88 d.click(0.907, 0.205)8990def watch_15s():91 time.sleep(0.1)92 for i in range(5):93 d.swipe(500, 500, 500, 300, 0.1)94 time.sleep(3)95 time.sleep(0.3)96 d.press("back")9798def taobao_task():99 time.sleep(1)100 if not exist_img('res/baba/task_taobao.png'):101 if not click_img('res/baba/ji_fei_liao.png'):102 return103 time.sleep(1)104 mark = d(text="去签到")105 if mark:106 mark.click()107 question = d(text="去答题")108 if question:109 question.click()110 time.sleep(0.5)111 #选B112 d.click(0.533, 0.904)113 #d.click(0.478, 0.9)114 time.sleep(1)115 #领奖励116 d(textContains="领取奖励").click_exists(timeout=1)117 time.sleep(1)118 click_img('res/baba/ji_fei_liao.png')119 taobo_life = d(text="去淘宝人生扔骰子(0/1)")120 if taobo_life:121 taobo_life.click()122 time.sleep(2)123 d.click(0.488, 0.677)124 time.sleep(2)125 d.click(0.488, 0.677)126 time.sleep(1)127 d.click(0.493, 0.645)128 time.sleep(1)129 d.press("back")130131 taote = d(text="去淘特领好礼(0/1)")132 if taote:133 taote.click()134 time.sleep(3)135 go_to_task()136137 task_list = ['逛精选好物(0/1)','逛精选商品(0/3)','逛精选商品(1/3)','逛精选商品(2/3)','搜一搜你心仪的宝贝(0/1)','浏览金币小镇得肥料(0/1)','浏览短视频(0/1)','逛精选好货(0/1)','浏览天天领现金(0/1)']138 for task_text in task_list:139 task_item = d(text=task_text)140 if task_item:141 print(task_item)142 task_item.click()143 time.sleep(1)144 shan_mo = d(text="闪魔")145 if shan_mo:146 shan_mo.click()147 if exist_img('res/baba/cash.png'):148 d.click(0.92, 0.254)149 watch_15s()150 go_to_task()151 d.swipe(500, 1000, 500, 700, 0.1)152 print('task_list process done')153 #上划154 d.swipe(500, 1000, 500, 800, 0.1)155 d(text="每日7点/12点/20点/22点各领1次").click_exists(timeout=1)156 time.sleep(1)157 d.click(0.92, 0.232)158 time.sleep(2)159 print('task process done')160161162#施肥163def fertilize():164 print('start fertilize')165 get_bound()166 if exist_img('res/baba/task_taobao.png'):167 d.click(0.92, 0.232)168 if not exist_img('res/baba/ji_fei_liao.png'):169 return170 while True:171 #点击兔子172 d.click(0.189, 0.684)173 #点击施肥174 d.click(0.546, 0.888)175 time.sleep(1)176 if click_img('res/baba/task_taobao.png'):177 # 施肥完成178 return179 item = d(text="立即领取")180 if item:181 item.click()182 time.sleep(0.5)183 #领取三个亲密度奖励184 d.click(0.209, 0.44)185 d.click(0.503, 0.434)186 d.click(0.807, 0.436)187 #点击关闭188 d.click(0.907, 0.205)189 #点击拆红包190 d.click(0.503, 0.709)191 d(text="关闭").click_exists(timeout=0.1)192 time.sleep(0.3)193194195196197198199def go_to_aplipay_task():200 if exist_img('res/baba/task_alipay.png'):201 return202 d.app_stop('com.eg.android.AlipayGphone')203 d.app_start('com.eg.android.AlipayGphone')204 d(text="芭芭农场").click(timeout=10)205 time.sleep(3)206 d(text="继续努力").click_exists(timeout=1)207 # 全部领取for i in range(3):208 d.click(0.822, 0.606)209 d(text="去领更多肥料").click_exists(timeout=1)210 # d(text="关闭").click_exists(timeout=1)211 # 点击集肥料212 d.click(0.867, 0.812)213214def alipay_task():215 time.sleep(1)216 if not exist_img('res/baba/task_alipay.png'):217 # 如果不在任务页签218 if not click_img('res/baba/ling_fei_liao_alipay.png'):219 return220 else:221 time.sleep(1)222 #签到223 d.click(0.827, 0.43)224 #浏览页面225226 task_list = ['逛一逛叫醒财神得大礼 (0/1)','逛一逛支付宝会员 (0/1)']227228 for task_text in task_list:229 print(task_text + ' start')230 item = d(text=task_text)231232 if not item:233 d.swipe(500, 1000, 500, 800, 0.2)234 d.swipe(500, 1000, 500, 800, 0.2)235 d.swipe(500, 1000, 500, 800, 0.2)236 item = d(text=task_text)237 if item:238 (x1,y1) = item.center()239 (x,y) = (x1+385,y1+20)240 (a, b) = d.window_size()241 print(x / a, y / b)242 d.click(x / a, y / b)243 #item.click()244 time.sleep(1)245 watch_15s()246 d(text="领取").click_exists(timeout=0.2)247 if not exist_img('res/baba/task_alipay.png'):248 go_to_aplipay_task()249 print(task_text + ' done')250 time.sleep(1)251 if exist_img('res/baba/task_alipay.png'):252 #领取合种奖励253 d.swipe(500, 1000, 500, 800, 0.1)254 d(text="领取").click_exists(timeout=0.2)255 #关闭任务页签256 d.click(0.925, 0.291)257258259#施肥260def alipay_fertilize():261 if not exist_img('res/baba/ling_fei_liao_alipay.png'):262 return263264 while True:265 #点击全部领取266 #todo267 # if exist_img('res/baba/xx.png')268 # d.click(0.812, 0.581)269 #点击施肥270 d.click(0.503, 0.815)271 item = d(text="点击领取")272 if item:273 item.click()274 time.sleep(0.3)275 #领取276 d.click(0.488, 0.666)277 time.sleep(0.3)278 if exist_img('res/baba/task_alipay.png'):279 #施肥完成280 break281282283284def start_alipay():285 d.app_stop('com.eg.android.AlipayGphone')286 d.app_start('com.eg.android.AlipayGphone')287 d(text="芭芭农场").click(timeout=10)288 time.sleep(3)289 d(text="继续努力").click_exists(timeout=1)290 #全部领取for i in range(3):291 d.click(0.822, 0.606)292 d(text="去领更多肥料").click_exists(timeout=1)293 #d(text="关闭").click_exists(timeout=1)294 #点击集肥料295 d.click(0.867, 0.812)296 #做任务297 alipay_task()298 #施肥299 alipay_fertilize()300# startTaobao()301# taobao_task()302# fertilize()303304# alipay_task()305#alipay_fertilize()306# start_taobao()307# start_alipay() ...

Full Screen

Full Screen

bot.py

Source:bot.py Github

copy

Full Screen

...9 return self.bot.sess10 def switch_screen(self, id_screen):11 util.logger('Switch screen: {}'.format(id_screen))12 if id_screen == ID_SCREEN_PROFILE:13 return self.bot.find_by_id('profile_tab').click_exists(timeout=2)14 elif id_screen == ID_SCREEN_SELECT_USERS:15 id_profile = self.bot.find_by_id('profile_tab')16 if id_profile.exists(timeout=2):17 return id_profile.long_click()18 return False19 elif id_screen == ID_SCREEN_OPTIONS:20 return self.bot.find_by_desc('Options').click_exists(timeout=2)21 elif id_screen == ID_SCREEN_UPLOAD_REEL:22 if self.switch_screen(ID_SCREEN_PROFILE):23 if self.bot.find_by_desc('Create New').click_exists(timeout=2):24 if self.bot.find_by_desc('Reel').click_exists(timeout=2):25 self.bot.find_by_id(26 'auxiliary_button').click_exists(timeout=2)27 if self.bot.find_by_id('dial_ar_effect_picker_left_side_button_container').click_exists(timeout=2):28 if self.bot.find_by_id('gallery_folder_menu').click_exists(timeout=2):29 if self.bot.find_by_desc('Instagram').click_exists(timeout=2):30 return True31 return False32 elif id_screen == ID_SCREEN_VIDEOS_SAVED:33 if self.bot.find_by_desc('Saved').click_exists(timeout=2):34 if self.bot.find_by_id('saved_collection_thumbnail').click_exists(timeout=5):35 return self.bot.find_by_desc('Saved reels').click_exists(timeout=5)36 return False37 def remove_video_saved(self, item_selected):38 util.logger('Remove video: Select item')39 if self.bot.find_by_desc('Options').click_exists(timeout=2):40 if self.bot.find_by_text('Select…').click_exists(timeout=2):41 if item_selected.click_exists(timeout=2):42 if self.bot.find_by_id('remove_button').click_exists(timeout=2):43 self.bot.find_by_text('Unsave').click_exists(timeout=2)44 util.logger('Remove video: Removed')45 return True46 return False47 def set_user(self, user):48 util.logger('Set user')49 if self.switch_screen(ID_SCREEN_SELECT_USERS):50 if user.click_exists(timeout=2):51 util.logger('=> User: {}'.format(user.info['text']))52 if self.bot.find_by_id('bottom_sheet_container_view').exists(timeout=2):53 self.bot.sess.press('back')54 return True55 return False56 def select_item_video_saved(self, item_selected):57 util.logger('Select item video saved')58 return item_selected.click_exists(timeout=2)59 def get_items_video_saved(self):60 util.logger('Get items video saved')61 result = []62 id_items_videos_saved = self.bot.find_by_id(63 'clips_tab_grid_recyclerview')64 if id_items_videos_saved.exists(timeout=2):65 items = self.bot.find_child_by_class(66 id_items_videos_saved, 'android.widget.RelativeLayout')67 if items.exists(timeout=2):68 result = items69 util.logger('=> Total: {}'.format(result.count))70 return result71 def get_users(self):72 util.logger('Get users')73 data_users = {}74 if self.switch_screen(ID_SCREEN_SELECT_USERS):75 users = self.bot.find_by_id('row_user_textview')76 if users.exists(timeout=10):77 if users.count > 2:78 for i in range(users.count-1):79 data_users[users[i].info['text']] = users[i]80 self.bot.sess.press('back')81 util.logger('=> Total: {}'.format(len(data_users)))82 return data_users83 def download_video(self):84 util.logger('Download video: Select video')85 if self.bot.find_by_id('direct_share_button').click_exists(timeout=4):86 if self.bot.find_by_desc('Add reel to your story').click_exists(timeout=10):87 if self.bot.find_by_id('overflow_button').click_exists(timeout=2):88 if self.bot.find_by_id('gallery_menu_save').click_exists(timeout=2):89 util.logger('Download video: Start')90 # waiting download91 msg_processing = self.bot.find_by_id('message')92 if msg_processing.exists(timeout=2):93 msg_processing.wait_gone(timeout=(60*10))94 util.logger('Download video: Saved')95 self.bot.sess.press('back')96 self.bot.find_by_desc(97 'Discard video').click_exists(timeout=4)98 self.bot.sess.press('back')99 self.bot.find_by_desc(100 'Back').click_exists(timeout=2)101 util.logger('Download video: End')102 return True103 return False104 def download_video_by_login(self, item, account):105 util.logger('Download video by login')106 if self.select_item_video_saved(item):107 if self.bot.find_by_desc('More').click_exists(timeout=4):108 if self.bot.find_by_text('Copy Link').click_exists(timeout=4):109 util.logger('=> Link: {}'.format(110 self.bot.sess.clipboard))111 self.bot.find_by_desc('Back').click_exists(timeout=2)112 return True...

Full Screen

Full Screen

uiauto.py

Source:uiauto.py Github

copy

Full Screen

...11 def device_initialize(self):12 self.device = uiautomator2.connect(self.ip)13 def click_by_text(self, text, contains=False, timeout=2):14 if contains:15 return self.device(textcontains=text).click_exists(timeout)16 return self.device(text=text).click_exists(timeout)17 def click_by_resourceId(self, resourceId, timeout):18 return self.device(resourceId=resourceId).click_exists(timeout)19 def click_by_description(self, description, contains=False, timeout=2):20 if contains:21 return self.device(descriptionContains=description).click_exists(timeout)22 return self.device(description=description).click_exists(timeout)23 def click_by_packageName(self, packageName, timeout):24 return self.device(packageName=packageName).click_exists(timeout)25 def click_list_text(self, list, contains=False, timeout=2):26 for text in list:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ATX automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful