2

I have an ExpandableListView and I would like to click() one of its childs.

I have tried LOADS OF different ways but I just can't seem to understand how Espresso works.

For instance, why does this code do not work?

onData(withId(R.id.execexpList)).onChildView(is(withId(200))).perform(click())

For some divine reason, it returns "ambiguous match" to my ExpandableLIstView and other ListView of mine, but they have DIFFERENT ids.

Can anyone help me out?

rafaelc
  • 57,686
  • 15
  • 58
  • 82
  • Shouldn't `withId` take a `R.id`? – Jared Burrows Jun 10 '16 at 01:04
  • @JaredBurrows I have set each row in my `ExpandableListView` to a specific ID. So thats why I hardcoded it – rafaelc Jun 10 '16 at 01:05
  • You used `setId` on the view? First try `withId(is(int))`. See https://developer.android.com/reference/android/support/test/espresso/matcher/ViewMatchers.html#withId(int). If that does not work try `setTag`. Then use https://developer.android.com/reference/android/support/test/espresso/matcher/ViewMatchers.html#withTagKey(int). – Jared Burrows Jun 10 '16 at 01:10
  • @JaredBurrows still ambiguous... How can I scroll down a `ExpandableListView`? It should be simple. I need to click a chilld of an `ExpandableListView` and thats it – rafaelc Jun 10 '16 at 01:17

1 Answers1

1

onData() is used to match an item inside the adapter of your ListView, not the actual view.

onChildView() is used to match a descendant of the ListView item that is matched in onData().

If you have multiple AdapterViews in hierarchy you have to use inAdapterView(Matcher<View>viewMatcher) instead.

Official API guide explains onData() usage in more details.

Be_Negative
  • 4,892
  • 1
  • 30
  • 33