This is the name of the popular online argument "UIAutomator cannot be used to search for controls in Chinese Text". The argument is uiautomator.

Source: Internet
Author: User

This is the name of the popular online argument "UIAutomator cannot be used to search for controls in Chinese Text". The argument is uiautomator.
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






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.