UIAutomator中滚动ListView获得目标TextView控件对象的经验点滴
来源:互联网 发布:圣思园 java web 编辑:程序博客网 时间:2024/06/13 15:54
当创建一个UiScrollable对象时,如果指定的参数是new UiSelector().scrollable(true),那么会出现以下问题
- 当可滚动控件(比如ListView)不满一页不需要滚动时,创建的UiSrollable对象返回值是为空的。
所以以下代码是错误的:
- //Find out the new added note entry
- UiScrollable noteList = new UiScrollable( new UiSelector().scrollable(true)); //would be null if the scrollable widget's not more than one page
- UiObject note = null;
- note = noteList.getChildByText(new UiSelector().className("android.widget.TextView"), "Note1", true);
- <pre name="code" class="java"> assertThat(note,notNullValue());
我们可以做一个增强,当判断返回的UiScrollable对象是空的时候,我们直接去当前页面查找目标控件:
- //Find out the new added note entry
- 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);
- }
- else {
- note = new UiObject(new UiSelector().text("Note1"));
- }
- assertThat(note,notNullValue());
- note.longClick();
另外一个个人认为更好的解决办法是,不要以“UiSelector().scrollable(true)”来初始化UiScrollable对象,而是明确的指定className为“android.widget.ListView"来初始化UiScrollable对象。实践证明这样子做的话就算ListView的内容很少不需要翻页时,也能够找到指定的当前页面的目标控件。
- //Find out the new added note entry
- UiScrollable noteList = new UiScrollable( new UiSelector().className("android.widget.ListView"));
- UiObject note = null;
- note = noteList.getChildByText(new UiSelector().className("android.widget.TextView"), "Note1", true);
- assertThat(note,notNullValue());
- note.longClick();
Item
Description
Warning
Author
天地会珠海分舵
转载请注明出处!
更多精彩文章请查看本人博客!
Blog Address
http://blog.csdn.net/zhubaitian
0 0
- UIAutomator中滚动ListView获得目标TextView控件对象的经验点滴
- UIAutomator中滚动ListView获得目标TextView控件对象的经验点滴
- UiAutomator中android.widget.ListView控件的子元素遍历
- 自定义控件:滚动的TextView跑马灯
- 怎么获取ListView和GridView适配器中item上TextView和ListView控件的值
- android设置在ListView中让TextView滚动
- 关于UIAutomator 滚动的steps
- UIAutomator的一点经验分享、!
- Android支持横行滚动的ListView控件
- Android支持横行滚动的ListView控件
- Android支持横行滚动的ListView控件
- Android支持横行滚动的ListView控件
- Android支持横行滚动的ListView控件
- Android支持横行滚动的ListView控件
- Android支持横行滚动的ListView控件
- Android支持横行滚动的ListView控件
- Android支持横行滚动的ListView控件
- Android支持横行滚动的ListView控件
- 中秘传媒:软文营销的优点
- js弹出窗口
- GridView的一些特殊属性
- eclipse launching workspace太慢的解决方法
- VC++: Linker options - /VERBOSE[:ICF |:LIB |:REF |:SAFESEH]
- UIAutomator中滚动ListView获得目标TextView控件对象的经验点滴
- WebView 自动换行
- IOS学习之——定位服务1 实现原理
- 一个SWT应用程序窗口最大化最小化问题?
- 字符串基本概念
- 高通平台android4.4 audio policy 学习记录(1):调用流程
- AFNetworking2.0源码解析<一>
- 计算机图像处理领域重要期刊汇总
- linux 权限掩码函数 umask 介绍