Appium element Positioning

Source: Internet
Author: User

Location by ID

The ID on Android is Resource-id

Driver.findelementbyid ("Com.tencent.mm:id/do")

Or

webelement element = Driver.findelement (By.id ("com.tencent.mm:id/do"));

Navigate by name

General text is name

Webelement el = driver.findelement (By.name ("nickname"));

Positioning via classname

ClassName is the class information inside the Uiautomator

Webelement el = driver.findelement (By.classname ("Android.widget.TextView"));

Positioning via XPath

XPath locates elements in Appium, performs slowly, is less efficient, and is seldom used

Webelement el = driver.findelement (By.xpath ("//android.widget.button[@index = ' 1 ')");

Positioning via Accessibilityid

The CONTENT-DESC information in Uiautomator is the anchor element

Webelement el = Driver.findelementbyaccessibilityid ("Sharebutton");

Locating elements by Androiduiautomator
Androiduiautomator is a powerful element positioning method, it is through the Android Uiautomator class library to find elements,
Findelement (By.androiduiautomator (String uiauto));

You can select Id,classname,name,description as the incoming string

Webelement el = Driver.findelementbyandroiduiautomator ("New Uiselector (). Description (\" sharebutton\ ")");

Method of the Text property, text information in Uiautomator

Driver.find_element_by_android_uiautomator (' New Uiselector (). Text ("Custom View"). Click () #text
Driver.find_element_by_android_uiautomator (' New Uiselector (). Textcontains ("View"). Click () #textContains
Driver.find_element_by_android_uiautomator (' New Uiselector (). Textstartswith ("Custom") '). Click () #textStartsWith
No EndsWith method
Driver.find_element_by_android_uiautomator (' New Uiselector (). Textmatches ("^custom.*"). Click () #textMatches
The use of regular expressions must match exactly, such as using "^custom" above is incorrect

Methods for classname Properties

#className

#classNameMatches

Methods for ResourceID Properties

#resourceId
#resourceIdMatches
Driver.find_element_by_android_uiautomator (' New Uiselector (). Resourceidmatches (". *id/text1$")

Positioning via ContentDescription

Methods for other properties of the element

Through Pseudo-XPath methods

by Uiselector.fromparent or Uiobject.getfromparent method

Quickly find sibling information for a parent element of a known element

Their functions are the same.

Getfromparent method

    1. Save = new UiObject (new uiselector (). Text ("Save");
    2. Assertequals (Save.gettext (), "Save");
    3. Delete = Save.getfromparent (new uiselector (). Text ("delete"));
    4. Assertequals (Delete.gettext (), "delete");

Promparent method

    1. Delete = new UiObject (new uiselector (). Text ("Save"). Fromparent (new uiselector (). Text (" Delete ")));
    2. Assertequals (Delete.gettext (), "delete");

by Uiselector.childselector or Uiobject.getchild method

Quickly find child elements in a known element

Getchild method

    1. UiObject Parentview = new UiObject (new uiselector (). ClassName ("Android.view.View"));
    2. Save = Parentview.getchild (new uiselector (). Text ("save"));
    3. Assertequals (Save.gettext (), "Save");

Childselector method

    1. Save = new UiObject (new uiselector (). ClassName ("Android.view.View"). Childselector (new Uiselector (). Text ("Save"));
    2. Assertequals (Save.gettext (), "Save");

Appium element 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.