是否可以使用UIAutomator获取ListView的所有子项?我面临的问题是 listView.getChildCount();
仅返回 View 中的子项数量。我尝试滚动并添加计数,但它工作不可靠。
UiScrollable listView = new UiScrollable(new UiSelector().scrollable(
true).className("android.widget.ListView"));
listView.setAsVerticalList();
listView.flingToBeginning(100);
int count = listView.getChildCount();
listView.scrollForward();
count += listView.getChildCount();
Log.d("STATE", "COUNT: " + count);
当需要滚动时,有没有可靠的方法来获取ListView的所有子项?
最佳答案
不幸的是,Uiautomator 只能看到当前屏幕上的对象...如果您想滚动到列表中的特定对象,您可以这样做:
listView.scrollIntoView(uiobjectYourLookingFor);
或者这个:
UiObject uiObjectYouWant = listView.getChild(newUiSelector().resourceId(com.yourappname:id/yourId");
这两个都会滚动到您指定的对象
关于android - 使用 UIAutomator 获取 android.widget.ListView 的所有子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40113763/