Appium+python Automated 31-android_uiautomator Positioning

Source: Internet
Author: User

Objective

Appium's predecessor is the framework of the Uiautomator that encapsulates Android, so some of Uiautomator's positioning methods can also be used

Text

1. Text positioning syntax

New Uiselector (). Text ("text literal")

2. When the text is longer, you can use textcontains fuzzy matching, as long as the text contains matching content.

New Uiselector (). Textcontains ("contains text")

3.textStartsWith is a match at the beginning of a text

New Uiselector (). Textstartswith ("Start with text text")

4. Regular matching textmatches, this need to match the regular expression, it is not an example.

New Uiselector (). Textmatches ("Regular expression")

  # coding:utf-8from appium Import webdriverdesired_caps = {' PlatformName ': ' Android ', ' DeviceName ': ' 127.0.0.1:62001 ', ' platformversion ': ' 4.4.2 ', ' apppackage ': ' Com.baidu.y                Uedu ', ' appactivity ': ' com.baidu.yuedu.splash.SplashActivity ', ' noreset ': ' true ', ' Resetkeyboard ': ' true ', ' Unicodekeyboard ': ' true '}driver = Webdriver. Remote (' Http://127.0.0.1:4723/wd/hub ', desired_caps) # etc Main Page activity appears driver.wait_activity (". Base.ui.MainActivity" , #) # 1.textloc_text = ' new Uiselector (). Text ("book") ' Driver.find_element_by_android_uiautomator (Loc_text). Click () # # 2.textcontains# loc_textcontains = ' new Uiselector (). Textcontains ("figure") ' # Driver.find_element_by_android_uiautomator (Loc_textcontains). Click () # # 3.textstartswith# Loc_textstart = ' new Uiselector (). Textstartswith ("figure") ' # Driver.find_ Element_by_android_uiautomator (Loc_textstart). Click ()  
ResourceId

1.resourceId Root by_id like

New Uiselector (). RESOURCEID ("id")

# resourceId定位loc_id = 'new UiSelector().resourceId("com.baidu.yuedu:id/webbooktitle")'driver.find_element_by_android_uiautomator(loc_id).click()

ClassName

1. The class attribute on the page is generally not unique and is mostly used in complex location. For example, by using the class attribute to position the ' rank ' button subscript is 2.

New Uiselector (). ClassName ("ClassName")

# className复数定位loc_class = 'new UiSelector().className("android.widget.TextView")'driver.find_elements_by_android_uiautomator(loc_class)[2].click()

Description

1. Since the Contenet-des property of this app is empty, it is not necessary to demonstrate the code, as in the above method.

New Uiselector (). Description ("Contenet-des property")

Reference Code
# coding:utf-8from Appium Import webdriverfrom time Import sleepdesired_caps = {' PlatformName ': ' Android ', ' DeviceName ': ' 127.0.0.1:62001 ', ' platformversion ': ' 4.4.2 ', ' apppackage ': '                 Com.baidu.yuedu ', ' appactivity ': ' com.baidu.yuedu.splash.SplashActivity ', ' noreset ': ' true ', ' Resetkeyboard ': ' true ', ' Unicodekeyboard ': ' true '}driver = Webdriver. Remote (' Http://127.0.0.1:4723/wd/hub ', desired_caps) # etc Main Page activity appears driver.wait_activity (". Base.ui.MainActivity" , #) # 1.textloc_text = ' new Uiselector (). Text ("book") ' Driver.find_element_by_android_uiautomator (Loc_text). Click () # # 2.textcontains# loc_textcontains = ' new Uiselector (). Textcontains ("figure") ' # Driver.find_element_by_android_uiautomator (Loc_textcontains). Click () # # 3.textstartswith# Loc_textstart = ' new Uiselector (). Textstartswith ("figure") ' # Driver.find_ Element_by_android_uiautomator (Loc_textstart). Click () SleeP (2) # ResourceId locate ' novel ' loc_id = ' new Uiselector (). ResourceId ("Com.baidu.yuedu:id/webbooktitle") ' Driver.find_element _by_android_uiautomator (loc_id). Click () Sleep (2) # ClassName complex location loc_class = ' New Uiselector (). ClassName (" Android.widget.TextView ") ' Driver.find_elements_by_android_uiautomator (Loc_class) [2].click ()

Appium+python Automation 31-android_uiautomator positioning

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.