1. 程式人生 > >UIAutomator通過中文文字查詢控制元件

UIAutomator通過中文文字查詢控制元件

之前轉過一個教程(http://blog.csdn.net/vivian_ljx/article/details/47613957)說UIAutomator不能通過中文文字查詢控制元件

其實是可以的,問題出在程式碼檔案的編碼格式上

解決方法:

選擇UTF-8


例子:

進入“設定”選單

package com.ljx.test;

import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class test extends UiAutomatorTestCase{

	 public void testDemo() throws UiObjectNotFoundException {  
	        getUiDevice().pressHome();  
	        // 進入設定選單  
	        UiObject settingApp = new UiObject(new UiSelector().text("設定"));  
	        settingApp.click();  
	        //休眠3秒  
	        try {  
	            Thread.sleep(3000);  
	        } catch (InterruptedException e1) {  
	            // TODO Auto-generated catch block  
	            e1.printStackTrace();  
	        }  	          
	    }  
}
執行結果如下: