diff --git a/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/utils/UiAutomatorUtils.java b/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/utils/UiAutomatorUtils.java index 12d0fe708b..2d9ed83b00 100644 --- a/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/utils/UiAutomatorUtils.java +++ b/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/utils/UiAutomatorUtils.java @@ -550,6 +550,28 @@ public static void handleButtonClickForObjectWithTextSafely(@NonNull final Strin } } + + /** + * Clicks the button element that contains the supplied text. + * Do not throw an exception if the button is not found. Waits + * for the button to exist with the supplied timeout before giving up + * and logging a warning. + * + * @param text the text on the button to click + * @param existsTimeout the maximum time to wait, in milliseconds, for the button + * to exist before giving up and logging a warning + */ + public static void handleButtonClickForObjectWithTextSafely(@NonNull final String text, final long existsTimeout) { + final UiObject button = obtainUiObjectWithText(text, existsTimeout); + + try { + button.click(); + } catch (final UiObjectNotFoundException e) { + Logger.w(TAG, "Button with text \"" + text + "\" was not found after waiting " + + existsTimeout + " ms: " + e.getMessage()); + } + } + /** * Clicks the button element that contains text matching the supplied regex */