I need to tap on an element that hardly stays for 3 seconds on the UI. Since it is vanishing from the UI within 3 seconds, my test is getting failed while finding the element. Is there a way to deal with it using appium?
@mykola-mokhnach We have host connected to the phone which runs appium , and controls ui elements by sending command to webdriver agent that is running on the phone.
We are seeing this issue in both. Currently, using resource-id for Android to locate this element.
if we take example of Teams app, where we receive a new chat we get a notification or a missed call notification in the app UI which stays for quite few seconds only, how to capture that elements?
// Java
boolean result = false;
long startTime = System.currentTimeMillis();
do {
try {
// id has package name
result = tap(driver.findElement(AppiumBy.id("id_with_package_name")));
// or slightly slower
// result = tap(driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().resourceId(\"any_id\")")));
// or we can disable add package name in appium settings and use first way
if (result)
break;
} catch (Exception ignored) {
}
sleep(100); // prevent too often search
} while (System.currentTimeMillis() < startTime + 10 * 1000); // 10 sec MAX wait
Assert.assertTrue(result, "Tap PopUp FAILED");
// tap() and sleep() use any your implementation you know