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
- Save = new UiObject (new uiselector (). Text ("Save");
- Assertequals (Save.gettext (), "Save");
- Delete = Save.getfromparent (new uiselector (). Text ("delete"));
- Assertequals (Delete.gettext (), "delete");
Promparent method
- Delete = new UiObject (new uiselector (). Text ("Save"). Fromparent (new uiselector (). Text (" Delete ")));
- Assertequals (Delete.gettext (), "delete");
by Uiselector.childselector or Uiobject.getchild method
Quickly find child elements in a known element
Getchild method
- UiObject Parentview = new UiObject (new uiselector (). ClassName ("Android.view.View"));
- Save = Parentview.getchild (new uiselector (). Text ("save"));
- Assertequals (Save.gettext (), "Save");
Childselector method
- Save = new UiObject (new uiselector (). ClassName ("Android.view.View"). Childselector (new Uiselector (). Text ("Save"));
- Assertequals (Save.gettext (), "Save");
Appium element Positioning