Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Espresso ListView click item

I have ListView with pictures and text. When I try to click item, I get error

android.support.test.espresso.AmbiguousViewMatcherException: 'with id: com.cifrasoft.telefm:id/cardsGridView' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.

I use the following code:

onData(hasToString(startsWith("Item Text")))
            .inAdapterView(withId(R.id.cardsGridView))
            .perform(click());

Can I click ListView using position of Adapter, without matches or startWith?

like image 889
Aleksandr Gorshkov Avatar asked Jan 19 '15 07:01

Aleksandr Gorshkov


1 Answers

Try with atPosition(). e.g.

onData(hasToString(startsWith("Item Text")))
            .inAdapterView(withId(R.id.cardsGridView)).atPosition(0)
            .perform(click());

with index 0, it will click on the first matching view found.

like image 171
user846316 Avatar answered Oct 19 '22 09:10

user846316