INNER CODE UNIT · Python
grant_usb_permission
etchdroid/etchdroid · appium-tests/etchdroid/actions.py:54
def grant_usb_permission(driver: Remote):
# The tap is swallowed if it lands while the confirmation activity is still settling,
# and then nothing requests permission at all. Retry, but keep the dialog wait short:
# Android often grants silently, and then no dialog is ever coming. The grant button
# disappearing is the signal that permission landed, however it was granted.
for _ in range(3):
try:
grant_btn = wait_for_element(driver, '//*[@resource-id="grantUsbPermissionButton"]', timeout=2)
except TimeoutException:
return
try:
grant_btn.click()
accept_usb_permission(driver, timeout=2)
return
except (TimeoutException, StaleElementReferenceException):
continue