Android Native page common element positioning method python use, code demo used by the beep of the client, the simulator is a night God simulator, try the most commonly used id,class,name,xpath positioning method, and some other positioning methods are webview specific, Keep updating ing
#coding =utf-8 ' Created on 2017/12/24 0024 @author: Changge ' "from Appium import webdriver import Time Desired_caps = {' PlatformName ': ' Android ', ' devicename ': ' 127.0.0.1:62001 ', ' platformversion ': ' 4.4.2 ', ' apppackage ': ' Tv.da Nmaku.bili ', ' appactivity ': ' tv.danmaku.bili.ui.splash.SplashActivity ', ' unicodekeyboard ': True, ' Resetkeyboard ' : True} Driver = Webdriver. Remote (' Http://127.0.0.1:4723/wd/hub ', desired_caps) # #休眠5s等待页面加载完成 Time.sleep (5) ' ' Various positioning methods ' to try ' #id定位, #id单数定位 with the Resource-id property, id unique Id_ele = driver.find_element_by_id (' Tv.danmaku.bili:id/largelabel ') print ("ID singular location:" + ID
_ele.text) #id复数定位 id_eles = driver.find_elements_by_id (' tv.danmaku.bili:id/tab_title ') texts = [] for ele in Id_eles: Texts.append (ele.text) print ("ID complex location:" + str (texts)) #class单数定位 # Class_ele = Driver.find_element_by_class_name (' Andro Id.support.v7.widget.RecyclerView ') # print (' class singular position: ' +class_ele.get_attribute (' class ') ') #class复数定位 class_eles = Driver.find_elements_by_cLass_name (' Android.widget.TextView ') texts = [] for ele in Class_eles:texts.append (ele.text) print (' class plural position: ' +str (t
exts) #name单数定位, through the Text property Name_ele = Driver.find_element_by_name (' recommended ') print (' Name singular location: ' +name_ele.text ') #name复数定位 Name_eles = Driver.find_elements_by_name (' edit recommended ') texts = [] for ele in Name_eles:texts.append (ele.text) print (' name plural Location: ' +str (texts)) #xpath单数定位 Xpath_ele = Driver.find_element_by_xpath ('//android.widget.textview[contains ' (@ Resource-id, "Tv.danmaku.bili:id/ranks")] print (' XPath singular position: ' +xpath_ele.text ') #xpath复数定位 xpath_eles = Driver.find_ Elements_by_xpath ('//android.widget.textview ') texts = [] for ele in Xpath_eles:texts.append (ele.text) print (' XPath plural
Location: ' +str (texts)) Driver.quit ()
Run Results