java +UIAutomator 通过中文文本查找控件 报错问题
2015-11-23 15:52
549 查看
<span style="font-family: SimSun; font-size: 14px; background-color: rgb(255, 255, 255);">在使用eclipse来编译java+uiautomator程序时,使用text属性来查找控件报错了,提示找不到控件UiOjbectNotFoundException</span>
百度搜索到的其他示例程序都是英文属性,难道uiautomator不支持中文text控件属性吗。再次把系统语言切换成英文后,再更改text name,运行居然可以了。
但这个UIAutomator是google弄的,不可能对unicode字符支持这么基础的东西都有问题啊,可怜网上UIAutomator与此相关的资源太少,几经艰辛才知道这个跟eclipse项目的Text file encoding选项有关系。原来问题还是出在自身上。
解决方法:把项目默认的Text file encoding从GBK改成UTF-8,重新打包运行
这次真的成功了。
附上实验代码:
import android.os.RemoteException; import com.android.uiautomator.core.UiDevice; 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 MessageTestCase extends UiAutomatorTestCase{ public void testDemo() throws UiObjectNotFoundException,RemoteException{ UiDevice device=getUiDevice(); device.pressHome(); sleep(2000); UiObject messageIcon=new UiObject(new UiSelector().text("信息")); assertTrue(" messageIcon not found", messageIcon.exists()); messageIcon.click(); sleep(3000); UiObject newMessage=new UiObject(new UiSelector().text("写短信")); assertTrue(" newMessage not found", newMessage.exists()); newMessage.click(); sleep(1000); UiObject addContact=new UiObject(new UiSelector().text("收件人")); assertTrue(" addContact not found", addContact.exists()); addContact.click(); addContact.setText("10086"); UiObject editMessage=new UiObject(new UiSelector().text("输入文本信息")); assertTrue(" editMessage not found", editMessage.exists()); editMessage.click(); editMessage.setText("11"); UiObject sendButton=new UiObject(new UiSelector().description("发送")); assertTrue(" sendButton not found", sendButton.exists()); sendButton.click(); UiObject sendCard=new UiObject(new UiSelector().text("中国移动")); sendCard.click(); } }
相关文章推荐
- UIImageView设置为圆形
- [置顶] MFC使用duilib的几种方式
- 如何使用require.js?
- iOS 根据uuid取得外设
- UITableview中怎么找到每个cell
- NSNotificationCenter(通知)与Key-Value Coding (KVC)与Key-Value Observing (KVO)
- UIImageView中图片尺寸模式
- Kibana User Guide [4.2] » Settings » Managing Fields
- [iOS]UITableView优化技巧
- 深度学习String、StringBuffer、StringBuilder
- impdp卡住,遇到等待事件Streams AQ: enqueue blocked on low memory
- [Leetcode]Range Sum Query - Immutable
- iOS8新特性 UIPresentationController(一)
- Kibana User Guide [4.2] »Settings
- Lesson 11 Not guilty
- UE4简单巡逻BehaviorTree的构建
- String,StringBuffer,StringBuilder
- easyui textbox 添加 onblur 失去焦点事件
- 定制UIButton中文字和图片的位置
- 053-14 You have a very large table that your users access frequently. Which of the following advisor