How to use child_by_text method in uiautomator

Best Python code snippet using uiautomator

util.py

Source:util.py Github

copy

Full Screen

...10def openWifi(d, flag):11 d.start_activity(component='com.android.settings/.MiuiSettings')12 assert d(text='WLAN').wait.exists(timeout=3000), 'can not launch settings in 3s'13 d(text='WLAN').click.wait()14 wifi = d(className='android.widget.LinearLayout').child_by_text('WLAN').sibling(className='android.widget.CheckBox')15 #Should open wifi16 if flag:17 i = 018 while not wifi.checked and i < 2:19 d(text='WLAN')[1].click.wait()20 sleep(3)21 i = i + 122 assert wifi.checked is True, 'wifi can not be opened'23 #if not wifi.checked:24 # d(text='WLAN')[1].click.wait()25 # assert d(className='android.widget.LinearLayout').child_by_text('WLAN').sibling(className='android.widget.CheckBox', checked=True).wait.exists(timeout=10000), "wifi can not be opened"26 # sleep(3)27 #Should close the wifi28 else:29 i = 030 while wifi.checked and i < 2:31 d(text='WLAN')[1].click.wait()32 sleep(3)33 i = i + 134 assert wifi.checked is False, 'wifi can not be closed'35 #if wifi.checked:36 # d(text='WLAN')[1].click.wait()37 # assert d(className='android.widget.LinearLayout').child_by_text('WLAN').sibling(className='android.widget.CheckBox', checked=False).wait.exists(timeout=10000), "wifi can not be closed"38 # sleep(3)39 40 #Wait for network switching41 d.press('home')42def backHome(d):43 d.press('back')44 sleep(1)45 d.press('back')46 sleep(1)47 d.press('back')48 d.press('home')49def fetchText():50 url = 'http://andymatthews.net/thought/'51 r = ''...

Full Screen

Full Screen

automation.py

Source:automation.py Github

copy

Full Screen

...26def scrolltoclickontext(text) :27 try:28 if d(className="android.widget.ListView").exists :29 d(className="android.widget.ListView").\30 child_by_text(text, allow_scroll_search=True, className="android.widget.LinearLayout", clickable=True).\31 click()32 elif d(className="android.support.v7.widget.RecyclerView").exists : 33 d(className="android.support.v7.widget.RecyclerView").\34 child_by_text(text, allow_scroll_search=True, className="android.widget.LinearLayout", clickable=True).\35 click()36 elif d(className="androidx.recyclerview.widget.RecyclerView").exists : 37 d(className="androidx.recyclerview.widget.RecyclerView").\38 child_by_text(text, allow_scroll_search=True, className="android.widget.LinearLayout", clickable=True).\39 click()40 elif d(className="android.widget.ScrollView").exists : 41 d(className="android.widget.ScrollView").\42 child_by_text(text, allow_scroll_search=True, className="android.widget.TextView", clickable=True).\43 click()44 return True45 except Exception as e:46 print(e)47 return False48 # d.screen.on()...

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