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?
Target a device by serial number Use the -s option followed by a device name to select on which device the adb command should run. The -s options should be first in line, before the command.
Open cmd type adb shell then press enter. Type ls to view files list.
Platform List is part of Android SDK and the best way to find the location is to open SDK manager and get the path. Appearance & Behaviour --> System Settings --> Android SDK You can get the path where SDK is installed and can edit the location as well. Show activity on this post. Type adb shell.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With