Skip to content Skip to sidebar Skip to footer

Clicking On One Of Many Views With Same Id In Espresso

I have a layout (A) that includes another layout (B) multiple times. Layout B contains a button with id R.id.my_button. As a result, layout A contains many of those buttons with th

Solution 1:

Probably, your layout B contains also some unique information, let's say TextView with unique name. In this case your code will look like this:

onView(allOf(withId(R.id.my_button), hasSibling(withText("unique name")))).perform(click());

More examples can be found in Espresso Wiki # ViewMatchers.

Post a Comment for "Clicking On One Of Many Views With Same Id In Espresso"