在Espresso中,当多个视图匹配时如何避免AmbiguousViewMatcherException [英] In Espresso, how to avoid AmbiguousViewMatcherException when multiple views match
问题描述
具有带有某些图像的gridView. gridView的单元格来自相同的预定义布局,具有相同的id和desc.
Having gridView which has some images. The gridView's cell comes out from same predefined layout, which has same id and desc.
R.id.item_image == 2131493330
R.id.item_image == 2131493330
onView(withId(is(R.id.item_image))).perform(click());
由于网格中的所有单元格都具有相同的ID,因此得到AmbiguousViewMatcherException
.
如何只选择其中的第一个或任何一个?
谢谢!
Since all cells in the grid have same id, it got AmbiguousViewMatcherException
.
How to just pick up first one or any of one of them?
Thanks!
android.support.test.espresso.AmbiguousViewMatcherException:'具有id:is< 2131493330>'匹配层次结构中的多个视图. 问题视图下方带有"**** MATCHES ****"标记.
android.support.test.espresso.AmbiguousViewMatcherException: 'with id: is <2131493330>' matches multiple views in the hierarchy. Problem views are marked with '****MATCHES****' below.
+ -------------> ImageView {id = 2131493330,res-name = item_image,desc = Image,能见度=可见,宽度= 262,高度= 262,has-focus = false,has-focusable = false,has-window-focus = true,is-clickable = false,is-enabled = true,is-focused = false,is-focusable = false,is-layout-requested = false,is- selected = false,root-is-layout-requested = false,has-input-connection = false,x = 0.0,y = 0.0} **** MATCHES ****
+------------->ImageView{id=2131493330, res-name=item_image, desc=Image, visibility=VISIBLE, width=262, height=262, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0} ****MATCHES****
+ -------------> ImageView {id = 2131493330,res-name = item_image,desc = Image,能见度=可见,宽度= 262,高度= 262,has-focus = false,has-focusable = false,has-window-focus = true,is-clickable = false,is-enabled = true,is-focused = false,is-focusable = false,is-layout-requested = false,is- selected = false,root-is-layout-requested = false,has-input-connection = false,x = 0.0,y = 0.0} **** MATCHES **** |
+------------->ImageView{id=2131493330, res-name=item_image, desc=Image, visibility=VISIBLE, width=262, height=262, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0} ****MATCHES**** |
推荐答案
您应使用onData()
在GridView
上进行操作:
You should use onData()
to operate on GridView
:
onData(withId(R.id.item_image))
.inAdapterView(withId(R.id.grid_adapter_id))
.atPosition(0)
.perform(click());
此代码将单击GridView
这篇关于在Espresso中,当多个视图匹配时如何避免AmbiguousViewMatcherException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!