C #-based Appium Automated testing Framework (Ⅱ): Android element targeting

Source: Internet
Author: User
Tags appium

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

Related Article

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.