0
A
回答
0
您需要创建一个自定义的匹配:
public static Matcher<View> nthChildOf(final Matcher<View> parentMatcher, final int childPosition) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("with "+childPosition+" child view of type parentMatcher");
}
@Override
public boolean matchesSafely(View view) {
if (!(view.getParent() instanceof ViewGroup)) {
return parentMatcher.matches(view.getParent());
}
ViewGroup group = (ViewGroup) view.getParent();
return parentMatcher.matches(view.getParent()) && group.getChildAt(childPosition).equals(view);
}
};
}
要使用它:
onView(nthChildOf(withId(R.id.directParentLinearLayout), 0).check(matches(withText("I am the first child"));
在你的情况,你还需要检查是具有唯一ID布局的后裔:
onView(nthChildOf(allOf(withId(R.id.directParentLinearLayout), isDescendantOfA(withId(R.id.linearLayoutWithUniqueId))), 0).check(matches(withText("I am the first child"));
相关问题
- 1. 访问元素的n-gram
- 2. 动态访问布局元素
- 3. 访问从主要布局包括布局的所有子元素
- 4. 问题,在第n个孩子奇/偶子元素
- 5. 在Haskell列表中访问列表中的第n个元素
- 6. 如何添加线性布局始终是RecyclerView中的第一个元素?
- 7. 通过base px * n第n个元素缩进每个第n个元素
- 8. 如何选择元素的第n个子元素?
- 9. Zen第n个元素
- 10. Xamarin.Forms布局可访问性
- 11. Flex的布局:显示第一要素,当两个子元素在同一行
- 12. 第n个孩子()问题
- 13. 访问元素的子元素
- 14. 发布模型的第n个属性
- 15. 访问子元素(jQuery的)
- 16. 访问第i个元素,它位于ArrayList的元素内
- 17. 获得集合的第n个元素
- 18. 计划中的第n个元素
- 19. 如何订购线性布局内的元素?
- 20. 访问对角线元素
- 21. 如何从Sitecore的另一个子布局访问子布局控制?
- 22. XPath来检索其母公司的第n个子元素的属性
- 23. 对于给定的键访问列表值的第n个元素:Python字典
- 24. 访问Nokogiri元素子元素
- 25. 框架布局内的线性布局
- 26. 如何均匀分布视图线性布局(这是另一个线性布局的孩子)?
- 27. Android中的线性布局问题
- 28. Android的线性布局问题
- 29. 如何访问片段内activity_main.xml中的线性布局
- 30. 每2个连续浮动元素添加break(第n个:子)