Android Automation test How to fill out XPath

Source: Internet
Author: User
Tags xpath

XPath gets control way 2.1 gets control by judging control properties

All properties of a control can be used as a judgment, such as whether its text,index,resource-id is clickable, and so on, for example:

2.1.1 Finding a target control with text
Webelement Target1 = Driver.findelementbyxpath ("//android.widget.textview[contains (@text, ' Note2 ')]"); Assertthat ( El.gettext (), Equalto ("Note2"));
2.1.2 to find the target control by index

If we use index to find the control Note2 as in the following way, it will fail because the XPath only says "I'm looking for a control of the Android.widget.TextView type index 0 on the page", But as the background says, we actually have 3 TextView controls, the top and the middle controls whose index is 0. So the final control is actually the first one to find the top text "Notes" TextView.

Webelement Target2 = Driver.findelementbyxpath ("//android.widget.textview[contains (@index, 0)]"); Assertthat ( El.gettext (), Equalto ("Note2"));

Then we'll have to figure out a way to add more paths, so that XPath can tell what is needed is the TextView of index 0 below, not the one above. Looking at the hierarchical structure of the uiautomatorviewer control, we find that the two TextView are forked from the linearlayout, so we should start with this path by specifying the array subscript we need to " Under LinearLayout the second framelayout below the listview below the TextView of index 0:

Webelement Target3 = Driver.findelementbyxpath ("//android.widget.linearlayout[1]/android.widget.framelayout/ Android.widget.listview/android.widget.textview[contains (@index, 0)] "Assertthat (El.gettext (), EqualTo (" Note2 ") );

Android Automation test How to fill out XPath

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.