0

onView(withId(R.id.feeding_name)).check(matches(isDisplayed())); causes AmbiguousViewMatcherException.

Due to multiple fragments on the screen the id "feeding_name" matches multiple views.

I am wondering, if there is any way to specify the parent of the view so that I could do something like onView(withIdAndParentId(R.id.feeding_name, R.id.fragment_show_feeding)).check(matches(isDisplayed()));

Gerke
  • 926
  • 1
  • 10
  • 20
  • 1
    You could try `allOf`, like `onView(allOf(withId(R.id.feeding_name), withParent(withId(R.id.fragment_show_feeding)))).check(matches(isDisplayed()));`. – Aaron Sep 21 '20 at 21:03
  • 1
    Works perfect, thank you! Make it an official answer and I will accept it. – Gerke Sep 22 '20 at 08:23

1 Answers1

2

You could try combination of matchers with allOf, like for example:

onView(allOf(withId(R.id.feeding_name), withParent(withId(R.id.fragment_show_feeding))))
    .check(matches(isDisplayed()));
Aaron
  • 3,764
  • 2
  • 8
  • 25