Skip to content Skip to sidebar Skip to footer

Onchildview And Hassiblings With Espresso

I am trying to access a button from a specific view. The same view is displayed 6 times. This is the code I am using. public void testTimeConfig(){ onData(withDesc('description

Solution 1:

Based on your last comment you should use onView() instead of onData(). I think you'll be able to click the button using hasSibling() - example

onView(allOf(withId(R.id.positive), hasSibling(withDesc(someString))))
    .perform(click());

or examples without your custom matcher (sibling view has text):

onView(allOf(withId(R.id.positive), hasSibling(withText(someString))))
    .perform(click());

or (sibling view has content description):

onView(allOf(withId(R.id.positive), hasSibling(withContentDescription(someString))))
    .perform(click());

EDITED:

OK, I'd try these two variants:

onView(allOf(withId(R.id.increaseGoalButton), isDescendantOfA(withId(R.id.timeGoalWidget))))
    .perform(click());

or

onView(allOf(withId(R.id.increaseGoalButton), withParent(withId(R.id.timeGoalWidget))))
    .perform(click());

Solution 2:

None of your content descriptions match the string "description" that's why it doesn't find anything.

Solution 3:

Assuming the button id is R.id.positive, and the id is unique in the current activity view, you can simply use:

onView(withId(R.id.positive)).perform(click());

Post a Comment for "Onchildview And Hassiblings With Espresso"