UiAutomator检查视图可见性

时间:2017-06-14 10:49:11

标签: android ui-testing uiautomator

如果在屏幕上显示,我试图在视图上执行点击(或多次点击)。我想要像这样的smth,但没有obj.isVisible()方法。

UiObject obj = device.findObject(new UiSelector().resourceId("ru.litres.android:id/container"));
UiObject objTop = device.findObject(new UiSelector().resourceId("ru.litres.android:id/container_top"));
while (obj.isVisible())
     objTop.click();

2 个答案:

答案 0 :(得分:2)

使用obj.exists()obj.waitForExists(timeout)

UiObject2方式:

UiDevice device = 
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
while(device.hasObject(By.res("ru.litres.android", "container"))) {
    objTop.click();
}

答案 1 :(得分:0)

UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
uiDevice.wait(Until.hasObject(By.res("ru.litres.android", "container")), 3000L);
UiObject2 objTop = uiDevice.findObject(By.res("ru.litres.android", "container"));
objTop.click();