[カスタムマッチャでそれを行うことができます - パブリック最終クラスCustomMatchers {
public static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
}
テストケースでそれを使用してください -
ViewInteraction textView9 = onView(
allOf(withText("ViewName"),
CustomMatchers.childAtPosition(
CustomMatchers.childAtPosition(withId(R.id.view)id), 1), 0), isDisplayed()))
チェック:http://stackoverflow.com/questions/38318086/android-espresso-total-count-of-elements-with-samerid-not-in-adapter-view – piotrek1543