This is the name of the popular online argument "uiautomator cannot search controls in Chinese Text ".

Source: Internet
Author: User
1. Problem description and cause

I believe that you will read this article at the beginning of uiautomator.

  • Overview of Android Automated Testing

This is because this article ranks first when you enter uiautomator for search.

However, there is a saying in this article that uiautomator does not support searching controls in Chinese text. This statement is harmless. If you have not investigated the control by yourself, uiautomator and its appium framework will also be easily abandoned, because what I will test at work now is the app on all Chinese interfaces.


The most harmful problem is that the problem is highlighted in red in the article. Although some comments in the article indicate that uiautomator actually supports Chinese search controls, however, I believe that many people will only read the text in technical articles like me.

2. Problem Analysis

After I finish writing the following code myself to verify the problem, the focus of the following code is to search for controls in the last few lines in Chinese (assuming the control already exists)

Package majcit.com. uiautomatordemo; import COM. android. uiautomator. core. uidevice; import COM. android. uiautomator. core. uiobject; import COM. android. uiautomator. core. uiobjectnotfoundexception; import COM. android. uiautomator. core. uiscrollable; import COM. android. uiautomator. core. uiselector; import COM. android. uiautomator. testrunner. uiautomatortestcase; import static Org. hamcrest. matchers. *; import static Org. hamcrest. matcherassert. assertthat; public class notepadtest extends uiautomatortestcase {public void testdemo () throws uiobjectnotfoundexception {uidevice device = getuidevice (); device. presshome (); // start notepad uiobject appnotes = new uiobject (New uiselector (). text ("Notes"); appnotes. click (); // sleep 3 seconds till the app get ready try {thread. sleep (3000);} catch (interruptedexception E1) {// todo auto-generated Catch Block e1.printstacktrace ();} // evke the system menu option device. pressmenu (); uiobject addnote = new uiobject (New uiselector (). text ("add note"); addnote. click (); // Add a new Note uiobject notecontent = new uiobject (New uiselector (). classname ("android. widget. edittext "); notecontent. cleartextfield (); notecontent. settext ("NOTE 1"); device. pressmenu (); uiobject save = new uiobject (New uiselector (). text ("save"); save. click (); // find out the new added Note Entry uiscrollable notelist = new uiscrollable (New uiselector (). classname ("android. widget. listview "); // uiscrollable notelist = new uiscrollable (New uiselector (). scrollable (true); uiobject note = NULL; If (notelist. exists () {Note = notelist. getchildbytext (New uiselector (). classname ("android. widget. textview ")," note1 ", true); // note = notelist. getchildbytext (New uiselector (). text ("note1"), "Chinese note", true);} else {Note = new uiobject (New uiselector (). text ("Chinese notes");} assertthat (note, notnullvalue (); note. longclick (); uiobject Delete = new uiobject (New uiselector (). text ("delete"); Delete. click ();}}
The following problems were encountered during the operation:


At that time, when I saw log saying "uiojbectnotfoundexception", the first response was the problem highlighted by the above blog. I thought that, as the author said, there was such a problem. But I think from another angle, this uiautomator is made by Google, and it is impossible to have problems with such basic support for Unicode characters. Therefore, Baidu Google asked me several times, poor web uiautomator related resources are rare. After a few hardships, I learned that this is related to the text file encoding option of the eclipse project. Now, when we think back, we should not first consider that the author of the blog is correct when a piece of video is garbled, as a netizen "Xiaoji" said, we should first consider whether the code file is encoded.

3. Solution

For example, change the default project text file encoding from GBK to UTF-8, re-package run



This is the name of the popular online argument "uiautomator cannot search controls in Chinese Text ".

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.