【问题标题】:Android UIAutomation get the last child (UiObject) of dynamic ViewAndroid UIAutomation获取动态View的最后一个孩子(UiObject)
【发布时间】:2014-08-26 00:15:13
【问题描述】:

我有一种情况,我需要使用 Android 的 UIAutomation 测试套件获取动态视图的“最后一个孩子”。

我有以下代码,但它不能正常工作:

UiSelector viewSelector = new UiSelector().resourceId("conversation_view").childSelector(new UiSelector().index(4));
UiObject conView = new UiObject(viewSelector);
//get the last child
UiObject lastChild = conView.getChild(new UiSelector().index(conView.getChildCount()-1));

除了“lastChild”部分外,一切正常。 “getChildCount”获取正确数量的子对象,所以我知道第一部分是检索正确的父对象。

它似乎搜索“所有”孩子,但我只希望它搜索直系孩子。

有人对我如何从 UiObject 获取最后一个“直接”子级有任何想法吗?

谢谢!

【问题讨论】:

    标签: java android ui-automation


    【解决方案1】:

    对于那些有兴趣的人。解决方案是创建一个集合,它将为您提供所有孩子的计数。从那里您可以使用“getChildByInstance”获取最后一个孩子。

    以下代码似乎可以解决问题:

    UiSelector viewSelector = new UiSelector().resourceId("conversation_container").childSelector(new UiSelector().scrollable(true));
    //get the last child
    UiCollection children = new UiCollection(viewSelector);
    int childCount = children.getChildCount(new UiSelector().className("android.view.View"));
    UiObject lastChild = children.getChildByInstance(new UiSelector().className("android.view.View"), childCount - 1);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-09
      • 1970-01-01
      • 2014-02-05
      相关资源
      最近更新 更多