Is it possible for adb shell
console to access an Android app's specific button using its id? or text?
I'm trying to automate the button click on the device. This is a web app accessed from a browser. So if I have that button id can I send an action to that button?
UI automator gives resource IDs, text, and the bounds of the UI element. An XML viewer or Chrome browser can be used to get a better view of the file.
adb pull $(adb shell uiautomator dump | grep -oP '[^ ]+.xml') /tmp/view.xml
The UI element's bounds can be be extracted and the mid point can be calculated. Replace text=
with resource-id=
or content-desc=
as needed.
coords=$(perl -ne 'printf "%d %d\n", ($1+$3)/2, ($2+$4)/2 if /text="MY_BUTTON_TEXT"[^>]*bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"/' /tmp/view.xml)
Now we have the coordinates of the UI element's center in $coords
and we just need to send a tap event.
adb shell input tap $coords