How to use child_by_instance method in uiautomator

Best Python code snippet using uiautomator

question.py

Source:question.py Github

copy

Full Screen

...55 if self.d(resourceId='cn.com.askparents.parentchart:id/anslist').exists(timeout=5):56 try:57 for num in range(nums):58 answer = {}59 time_content = self.d(resourceId="cn.com.askparents.parentchart:id/anslist").child_by_instance(60 resourceId="cn.com.askparents.parentchart:id/text_time", inst=num).get_text()61 answer_content = self.d(62 resourceId="cn.com.askparents.parentchart:id/anslist").child_by_instance(63 resourceId="cn.com.askparents.parentchart:id/text_content", inst=num).get_text()64 answer_name = self.d(resourceId="cn.com.askparents.parentchart:id/anslist").child_by_instance(65 resourceId="cn.com.askparents.parentchart:id/text_name", inst=num).get_text()66 answer['answer_time'] = self.parse_time(time_content)67 answer['answer_name'] = answer_name68 answer['answer_content'] = answer_content69 # if self.d(resourceId='cn.com.askparents.parentchart:id/ll_answelist').exists(timeout=3):70 # if self.d(resourceId='cn.com.askparents.parentchart:id/text_fromname').exists(timeout=3):71 # reply_name = self.d.xpath(72 # '//*[@resource-id="cn.com.askparents.parentchart:id/text_fromname"]').get_text()73 # reply_content = self.d.xpath(74 # '//*[@resource-id="cn.com.askparents.parentchart:id/ll_content"]/android.widget.TextView[1]').get_text()75 # reply_time = self.d.xpath(76 # '//*[@resource-id="cn.com.askparents.parentchart:id/ll_content"]/android.widget.TextView[2]').get_text()77 # answer['reply_name'] = reply_name78 # answer['reply_content'] = reply_content79 # answer['reply_time'] = self.parse_time(reply_time)80 # print('{}次{}'.format(num, answer))81 answer_list.append(answer)82 except Exception as e:83 print(e)84 # self.swipe_down(1)85 finally:86 return answer_list87 else:88 return answer_list89 def merge_question_answers(self, question, answers):90 question['answers_num'] = len(answers)91 for index, answer in enumerate(answers, 1):92 tmp_dict = dict()93 tmp_dict['answer' + str(index)] = '{},{}:{}'.format(answer['answer_name'],94 answer['answer_time'],95 answer['answer_content'])96 question.update(tmp_dict)97 def run(self):98 signature_set = set()99 repeat_count = 0100 while True:101 if self.d(text=self.tab_text).exists(timeout=5):102 self.d(text=self.tab_text).click()103 if self.d(resourceId='cn.com.askparents.parentchart:id/text_question').exists(timeout=5):104 self.d(resourceId="cn.com.askparents.parentchart:id/text_question").click()105 question = self.get_question()106 if question:107 answers = self.get_answers()108 self.merge_question_answers(question, answers)109 signature = str(question)110 if signature in signature_set:111 repeat_count += 1112 else:113 repeat_count = 0114 signature_set.add(signature)115 self.mogo.add_one(self.tab_text, question)116 print('已经爬取了{}条数据'.format(len(signature_set)))117 print(question)118 if self.d(resourceId='cn.com.askparents.parentchart:id/img_back').exists(timeout=5):119 self.d(resourceId="cn.com.askparents.parentchart:id/img_back").click()120 if repeat_count >= 10:121 print('到达底部')122 # break123 self.swipe_down(2)124 def get_one_page(self):125 question = self.get_question()126 self.merge_question_answers(question, self.get_answers())127 self.mogo.add_one(self.tab_text, question)128 print(question)129 def get_one_answer(self, num=0):130 result = {}131 if self.d(resourceId='cn.com.askparents.parentchart:id/text_content').exists(timeout=5):132 time_content = self.d(resourceId="cn.com.askparents.parentchart:id/anslist").child_by_instance(133 resourceId="cn.com.askparents.parentchart:id/text_time", inst=num).get_text()134 answer_content = self.d(135 resourceId="cn.com.askparents.parentchart:id/anslist").child_by_instance(136 resourceId="cn.com.askparents.parentchart:id/text_content", inst=num).get_text()137 answer_name = self.d(resourceId="cn.com.askparents.parentchart:id/anslist").child_by_instance(138 resourceId="cn.com.askparents.parentchart:id/text_name", inst=num).get_text()139 result['time_content'] = self.parse_time(time_content)140 result['answer_content'] = answer_content141 result['answer_name'] = answer_name142 # if self.d(resourceId='cn.com.askparents.parentchart:id/ll_answelist').exists(timeout=3):143 # reply_name = self.d.xpath(144 # '//*[@resource-id="cn.com.askparents.parentchart:id/text_fromname"]').get_text()145 # reply_content = self.d.xpath(146 # '//*[@resource-id="cn.com.askparents.parentchart:id/ll_content"]/android.widget.TextView[1]').get_text()147 # reply_time = self.d.xpath(148 # '//*[@resource-id="cn.com.askparents.parentchart:id/ll_content"]/android.widget.TextView[2]').get_text()149 # result['reply_name'] = reply_name150 # result['reply_content'] = reply_content151 # result['reply_time'] = self.parse_time(reply_time)...

Full Screen

Full Screen

leave.py

Source:leave.py Github

copy

Full Screen

...33 button.leaveFilter().click()34 time.sleep(1)35 button.deviceBack()36 print("--device back button is clicked in inbox filter")37 button.listView().child_by_instance(1).click()38 print("--leave card opened in inbox")39 time.sleep(1)40 button.deviceBack()41 print("--device back button clicked in leave details page")42 button.listView().child_by_instance(1).click()43 button.back().click()44 print("--app back button is clicked in leave details page")45 button.leaveFilter().click()46 button.scrollView().scroll.to(text='Approved')47 print("--scrolled in filter to find Approved status")48 button.findTextContain('Approved').click()49 print("--approved status selected")50 button.findTextContain('Apply').click()51 print("--filter applied with approved status")52 button.listView().fling.toBeginning()53 print("--refresh to reset filter")54 button.teamViewLeave().click()55 print("--team view opened")56 time.sleep(1)57 button.deviceBack()58 print("--device back button is clicked in team view")59 button.teamViewLeave().click()60 button.back().click()61 print("--app back button is clicked in team view")62 button.teamViewLeave().click()63 button.listView().fling.toEnd()64 print("--scrolled till end in team view")65 button.leaveTeamViewSearch().click()66 print("--search opened in team view")67 button.enterText('Nikesh')68 print("--text entered in search box")69 time.sleep(2)70 button.leaveTeamViewSearchClear().click()71 print("--search key cleared")72 button.leaveTeamViewSearchClear().click()73 print("--search box closed")74 button.leaveFilter().click()75 print("--leave filter opened in team inbox")76 time.sleep(1)77 button.deviceBack()78 print("--device back button is clicked in team view filter")79 button.leaveFilter().click()80 button.appBack().click()81 button.leaveFilter().click()82 button.findTextContain('study').click()83 print("--study leave selected in filter")84 button.findTextContain("Apply").click()85 print("--filter applied")86 button.listView().fling.toBeginning()87 print("refreshed to remove filter")88 button.listView().child_by_instance(1).click()89 print("--leave card opened in team view")90 time.sleep(1)91 button.deviceBack()92 print("--device back button clicked in leave details page")93 button.listView().child_by_instance(1).click()94 button.backLeaveDetaislPage().click()95 print("--app back button clicked in leave details page")96 button.listView().child_by_instance(1).click()97 button.leaveDetailsUserHeader().click()98 print("--user profile opened from leave details page")99 time.sleep(1)100 button.deviceBack()101 resp.append(True)102 resp.append(printMsg.printSuccess(os.path.basename(__file__)))103 except Exception as e:104 # button.takeScreenShort(os.path.basename(__file__))105 resp.append(False)106 resp.append(printMsg.printException(e, os.path.basename(__file__)))107 return resp108if __name__ == "__main__":...

Full Screen

Full Screen

AppRequest.py

Source:AppRequest.py Github

copy

Full Screen

...29 self.check_pkg(view + 1)30 def check_pkg(self, positon):31 print(positon)32 index_positon_info = d(className="android.widget.ListView", resourceId="android:id/list") \33 .child_by_instance(positon).info34 print(index_positon_info)35 # class_name_ = index_positon_info['className']36 # if not class_name_ == 'android.widget.ListView':37 # d(className="android.widget.ListView", resourceId="android:id/list") \38 # .child_by_instance(positon).click()39 # if class_name_ == 'android.widget.LinearLayout':40 # print(class_name_)41 # info = d(className=class_name_).info()42 # print(info)43 # d.wait(5)44 # d.press.back()45if __name__ == '__main__':...

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 uiautomator 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