Appium Python automated Test series Android Uiautomator Ultimate Positioning (vii)

Source: Internet
Author: User
Tags appium

Android Uiautomator Text Location

Someone may not know why Android Uiautomator is the ultimate location, and what does Android Uiautomator have to do with Appium? If some of the previous scripts have been written and found that some of the elements are not well positioned, then the Android Uiautomator is needed to locate them, which is a very powerful way to locate the android that comes with Android Uiautomator of the class library to find elements, are directly published by the official method to find it can not find it?

First look at our picture below:

In the above image we do not use Appium encapsulation method, directly using the Android Uiautomator to locate the results are as follows:

user = new Uiobject (new Uiselector (). Text ("Please enter phone number") User.settext ("test")

It's okay to read these two sentences, because what we're going to talk about is the way Appium has encapsulated him, and here's just a look at how his original approach was done. First he will come out with a new object based on your location information, and then do the work on top of your new object. Let's take a look at the implementation method in Appium:

Ele = Self.driver.find_element_by_android_uiautomator (' New Uiselector (). Text ("Please enter phone number") Ele.send_keys ("123")

  

Two code comparisons we can find that their similarities are just the same as the last location information, namely: New Uiselector (). Text ("Please enter phone number")

What do you mean by that sentence? Simple words are based on certain conditions to find the element, our condition is that the Text property is "Please enter the phone number", and then according to the picture to understand is not very easy?

Android Uiautomator element positioning is actually the same as the positioning of appium, or he is more than appium positioning method and better application, not only this one, he is only classname, ID and other positioning, but also support fuzzy matching to locate, Does it feel bigger on it? Let's briefly introduce these positioning methods.

6.6.2 Uiautomator text Blur location

Fuzzy positioning so the name of meaning, through the text part of the information can be positioned, we directly look at the code:

Ele = Self.driver.find_element_by_android_uiautomator (' New Uiselector () textcontains ("Please enter Hand") Ele.send_keys ("123") )

  

In the above code we just turned the. Text () method into. Textcontains (), and it's good to pass in the fuzzy data in the method. See if anyone here has thought about a problem, since there is a similar fuzzy search, then there is not like the regular expression of the same search? The answer is yes, look at our methods below.

6.6.3 textmatches Regular Match lookup

Textmatches so the name of meaning is through the regular to find and locate, he is also through the Text property to do regular matching, we directly look at the code:

Ele = Self.driver.find_element_by_android_uiautomator (' New Uiselector (). Textmatches ("^ Please enter hand. *") ') Ele.send_keys (" 123 ")

  

Some of the above matching information may be some just do the test of small partners do not know, this does not matter, down can search the regular expression tutorial, a little bit to understand.

6.6.4 Uiautomator ResourceID Positioning

ResourceID positioning and Appium package ID positioning is the same, but here will be written into the uiautomator of the wording, see the following code:

Ele = Self.driver.find_element_by_android_uiautomator (' New Uiselector (). ResourceId ("Cn.com.open.mooc:id/et_phone_ Edit ") Ele.send_keys (' 234 ')

  

By comparing the above code with the previous code, you may find that they are the same in front of each other, but in the positioning of the time there are some changes, the text transformation into a ResourceID can be, that is, the Page object property information changes, the other methods are the same. The following other methods I will not waste space, just to give you a simple case show.

6.6.5 resourceidmatches Positioning

Regular match positioning by ID

Ele = Self.driver.find_element_by_android_uiautomator (' New Uiselector (). Resourceidmatches (". +et_phone_edit") ') Ele.send_keys (' 234 ')

  

6.6.6 uiautomator classname positioning by calling Android Uiautomator using classname

  

Ele = Self.driver.find_element_by_android_uiautomator (' New Uiselector (). ClassName ("Android.widget.EditText") ') Ele.send_keys (' 234 ')

  

6.6.7 uiautomator classnamematches Positioning

Positioning by classname regular match

Ele = Self.driver.find_element_by_android_uiautomator (' New Uiselector (). Classnamematches (". *edittext") ') Ele.send_ Keys (' 234 ')

Through the above study I believe that we have a certain understanding of the positioning of the uiautomator, but I want to tell you that this is not all, there are many a lot of positioning methods, the need for everyone in the future to accumulate in the study, I can not all the methods to tell everyone, Here is just to give everyone a start, but I hope that everyone in the study of positioning is not just looking at the location of Appium, after all, he is also encapsulated uiautomator positioning, so in the learning appium at the same time uiautomator to learn about this is very helpful, And for the future to upgrade themselves and the work of re-encapsulation appium have a lot of help.

Appium Python automated Test series Android Uiautomator Ultimate Positioning (vii)

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.