2

I would like to click on the first matching row in recyclerView which item has descendant matching to specific text.

For now, I have

 onView(withId(R.id.news)).perform(
                actionOnItem(hasDescendant(withText("text")),click())
        )

which throws ambiguousViewMatcherException. I tried to add first matcher from here

onView(withId(R.id.news)).perform(
                    actionOnItem(hasDescendant(first(withText("text"))),click())
            )

but it time out.

public static Matcher<View> first(Matcher<View> expected ){

    return new TypeSafeMatcher<View>() {
        private boolean first = false;

        @Override
        protected boolean matchesSafely(View item) {

            if( expected.matches(item) && !first ){
                return first = true;
            }

            return false;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("Matcher.first( " + expected.toString() + " )" );
        }
    };
}
hjchin
  • 864
  • 2
  • 8
  • 25
  • I think the answer to [this](https://stackoverflow.com/q/52737309/6654475) question may help you. – Francislainy Campos Nov 06 '18 at 09:25
  • You need to make custom macher for RecyclerView check [this](https://stackoverflow.com/a/52828004/10111447) out. – Anass NAZIH Aug 30 '19 at 09:39
  • thanks for the comment but this question has been quite a bit old and I didn't continue this work anymore – hjchin Sep 20 '19 at 05:30
  • @AnassNAZIH What if I don't know the position I want to click? Just like in the original question, I want to select the first RecyclerView item that contains some text when there are multiple items with that same text. – Just The Highlights Oct 02 '19 at 17:37

0 Answers0