appium-Android Native-Python usage of common element positioning APIs (ii) __python

Source: Internet
Author: User
Tags xpath appium

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.