We know that the principle of appium is to provide the element positioning function through Remotewebdriver, and then operate according to the positioned elements, such as:
protected Static Remotewebdriver calculatorsession; Calculatorsession.findelementbyname ("one"). Click ();
The focus of the work is to locate the corresponding element, and Appiuim provides a number of methods for locating elements, including:
findelement (by); Findelementbyclassname (string className); Findelementbycssselector (string cssselector); Findelementbyid (string ID); Findelementbylinktext (string linkText); Findelementbyname (string name); Findelementbypartiallinktext (string partiallinktext); Findelementbytagname (string tagName); Findelementbyxpath (string XPath);
So our next job is to find the elements that apply to these methods.
Elements under the Android system can be positioned via Uiautomatorviewer, Uiautomatorviewer is the element Locator tool that comes with the Android SDK, in Android_sdk\tools\ Open the file directly under the bin path.
Launch the Android simulator or link Android real machine, click the Phone button in the upper left corner to capture the app's current interface, click on any of the top left corner of the phone icon can be, the difference is only the latter on the level of compression, This situation is more advantageous for large numbers of apps that use arrays or generic fills, and does not target elements that are empty or have the same name ID:
For example, we locate this share button, we can see this button's Resource-id (with ID positioning), class (classname positioning) and text (with linktext positioning), we in the positioning, priority to the unique element attributes to locate, Here we use the text to locate, click the code of this element can be as follows:
Public void TestCase1 () { Calculatorsession.findelementbylinktext (" share "). Click (); }
C #-based Appium Automated testing Framework (Ⅱ): Android element targeting