Small partners who are familiar with selenium automation should know that Webdriver provides eight element positioning methods:
Id
Name
Class name
Tag name
Link text
Partial link text
Xpath
CSS Selector
appium element positioning and webdriver slightly different, specific differences, the following will be described in detail, Before we do this, we open uiautomatorviewer.bat (under the Sdk/tools path)
Appium element Positioning one: locating by Id
As shown in Resource-id is the ID we're looking for.
How to use:
Driver.findelement (By.id ("Com.android.calculator2:id/digit_9"))
appium element Positioning two: by Class Name positioning
There is more than one view used with ClassName , so you should iterate through the views you get, then narrow down the search criteria to get the target control. Not recommended for use
Driver.findelement (By.classname ("Android.widget.Button"));
Appium element Positioning three: positioning via XPath
Find the parent tag class
Driver.findelement (By.xpath ("android.widget.framelayout/android.support.v4.view.viewpager/ Android.widget.Button "))
Appium element positioning four: locating by accessibility ID
This method belongs toAppiumThe location method of the extension. Accessibility IDon Android it is equivalent to contentdescription. This property is handy for some physiological functions that are defective
People using the application. For example, we have aImageViewThere is a color complex picture, perhaps some blindness colour-blind people, can not tell the picture of what is painted. If a user installs a secondary browse tool such asTalkBack, TalkBack will be loud .
Read what the user is currently browsing.TextViewControlTalkBackYou can read the contents directly, butImageView, TalkBackyou can only read the value of contentdescription and tell the user what the picture is.
Since this is a hidden property,Android The various properties used to find controls may be missing or duplicated (such as id duplicates, such as a list All the items below may be called
View contentdescriptioncontentdescription property. It is the element's content-desc
/span>
Driver.findelementbyaccessibilityid ("Plus"). Click ();
Appium element Positioning five: positioning via Android Uiautomator
androiduiautomator is a powerful element positioning method, it is through the Android Uiautomator class library to find elements, android uiautomator
4, through the uiautomatorviewer to achieve the Appium element positioning