簡體   English   中英

UiAutomator檢查視圖可見性

[英]UiAutomator check view visibility

如果屏幕上可見,我試圖在視圖上執行單擊(或多次單擊)。 我想要這樣的東西,但是沒有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();

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

UiObject2的方式:

UiDevice device = 
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
while(device.hasObject(By.res("ru.litres.android", "container"))) {
    objTop.click();
}
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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM