你如何链接UiSelector

时间:2016-05-03 18:54:24

标签: appium uiautomator android-uiautomator

我很难学习如何使用android.support.test.uiautomator中的UiSelector类。我曾多次尝试将这些方法联系起来但却无法找到方法。我试过的最后一件事看起来像这样:

self.driver.find_element_by_android_uiautomator('
                     new UiSelector().fromParent("
                     new UiSelector().resourceId(\"com.android.app:id/content_container\")").index(1)')

如何使用UiSelector从父对象获取子对象?有人能帮助我理解这个吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

如果您正在使用Appium,我不确定它是怎么回事。但是在基本的UIAutomator上,您不必链接新的UiSelector(),您可以使用链接属性构建一个UiSelector实例。 例如

UiSelector selector = new UiSelector().resourceId(<resource_id>).className(<className>).clickable(true);

UiObject object = device.findObject(selector);

我假设你有一个UiDevice.device。

您也可以使用BySelector并获取UiObject2:

BySelector selector = By.clazz(<class_name>).res(<resource_id>);
List<UiObject2> objects = device.findObjects(selector);