android - in Espresso, how to choose one the view who have same id to avoid AmbiguousViewMatcherException -


having gridview has images. gridview's cell comes out same predefined layout, has same id , desc.

r.id.item_image == 2131493330

onview(withid(is(r.id.item_image))).perform(click()); 

since cells in grid have same id, got ambiguousviewmatcherexception. how pick first 1 or of 1 of them? thanks!

android.support.test.espresso.ambiguousviewmatcherexception: 'with id: <2131493330>' matches multiple views in hierarchy. problem views marked '****matches****' below.

+------------->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, 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**** |

you should use ondata() operate on gridview:

ondata(withid(r.id.item_image))         .inadapterview(withid(r.id.grid_adapter_id))         .atposition(0)         .perform(click()); 

this code click on image inside first item in gridview


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -