Appium to get control instances based on XPath essay

Source: Internet
Author: User
Tags appium

Appium has a number of ways to get controls, as described in the article, "Appium-based control localization practices for various findelement on Android ." One is to locate the control based on the XPath on the page where the control resides.

This article tries to try to explain to appium how to use XPath to locate the control, if there is an incorrect place, please point out.

1. Background the experiment object that this article tries to use is the SDK's own Notepad application instance. If there are already two notes each are "note1" and "Note2" added to Notepad above. All we have to do is try to use the XPath method to locate the TextView control below the ListView "Note2".

Note that there are 3 textview types of controls on the interface:

    • Top of the Textview,index as the entire ListView title text for "Notes" is 0
    • The middle text for "Note2" of the Textview,index is also 0
    • The following text is the TextView of "note1". Index is 1


2. XPath gets control way 2.1 All properties of a control control by inferring control properties can be used as inferences, for example its text,index. Resource-id whether clickable, such as: 2.1.1 Find the target control by text
    el = Driver.findelementbyxpath ("//android.widget.textview[contains (@text, ' Note2 ')]");        Assertthat (El.gettext (), Equalto ("Note2"));
2.1.2 to find the target control by index it is assumed that we will fail if we use index to find the control Note2 as in the following way. Since the XPath simply says "I'm looking for a control with index 0 on the Android.widget.TextView type on the page," We actually have 3 TextView controls, as the background says. The top and middle controls have their index at 0. So finally the control is actually the Appium first to find the top text for "Notes" TextView.

    el = Driver.findelementbyxpath ("//android.widget.textview[contains (@index, 0)]");        Assertthat (El.gettext (), Equalto ("Note2"));
Then we have to find a way to add the path, so that the XPath can distinguish the need is the following index is 0 textview. Rather than the above. Viewing the hierarchical structure of the Uiautomatorviewer control, it was found that the two textview were forked from the beginning of linearlayout. So we should start with this path by specifying that the array subscript we need is "linearlayout below the second framelayout below the listview below the TextView with index 0:
        el = Driver.findelementbyxpath ("//android.widget.linearlayout[1]/android.widget.framelayout/ Android.widget.listview/android.widget.textview[contains (@index, 0)] ");        Assertthat (El.gettext (), Equalto ("Note2"));
2.1.3 to find the target control through other propertiesTBD, these are not listed, the above two demo sample to achieve the
2.2 Getting control by specifying the location of the selection collection in my practice and understanding, getting controls in this way is unreliable, at least two questions.
    • Issue 1: The control's position in the collection is not controllable.
        el = Driver.findelementbyxpath ("//android.widget.textview[1]");        Assertthat (El.gettext (), Equalto ("Note2"));
The above example I would like to uiautomatorviewer inside the upper and lower 3 textview in the middle of the find out, but the results returned to my really top of the "Notes."
    • Issue 2: Finding the specified set of elements by adding a path layer limit does not work.
        el = Driver.findelementbyxpath ("//android.widget.framelayout[1]/android.widget.linearlayout[1]/ Android.widget.framelayout/android.widget.listview/android.widget.textview[0] ");        Assertthat (El.gettext (), Equalto ("Note2"));
The above example is my intention to indicate that the "I want the control is the first of the two TextView controls below the ListView" by adding a parent path restriction. But returned to me is "an unknown server-side error occurred while processing the command", feeling is out of bounds the appearance. 2.4 XPath how to use the official manual for other non-mainstream access control by XPath. Please refer to the official XPath manual in Chinese version: http://wenku.baidu.com/link?url= Tldn9x4ucgmzyykj4dpsgsdbshxew6w8btyqqaxd0ktmy6lbqqliil9fhtczmdieo8o5zkv-fzlw96mfgvmwz-qz35epobyv8hkltuyxbv3

author

Autonomous blog

csdn

Heaven Zhuhai Sub-rudder

http://techgogogo.com


Service Number : Techgogogo

Scan Code :

Tp=webp "style=" max-width:100%; margin:0px; padding:0px; Height:auto!important; Word-wrap:break-word!important; Width:auto!important; Visibility:visible!important ">

Http://blog.csdn.net/zhubaitian




Appium to get control instances based on XPath essay

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.