Reputation: 4638
Using appium for android app automation. Not able to click on the "Done" button displayed on the phone keyboard. Can someone help is there any way we can click on the Android phone done button using ADB Shell commands?
Upvotes: 5
Views: 6215
Reputation: 59
On Android keyboard can be hidden effectively using next command:
((AndroidDriver) appiumDriver).pressKey(new KeyEvent(AndroidKey.BACK));
Using ENTER key can cause problems if focus is into input field. Then keyboard won't be hidden and Carriage Return will be executed.
Using Appium method:
((AndroidDriver) appiumDriver).hideKeyboard();
will also cause problem if keyboard have to be hidden from the popup or BottomSheet dialog. Then dialog will also be closed.
Also, using unicodeKeyboard
capability is now deprecated.
Upvotes: 0
Reputation: 17813
As indirect solution I use key_event TAB (61) to switch focus to action button then I send key_event ENTER (66)
adb shell input keyevent 61
Then:
adb shell input keyevent 66
Upvotes: 2
Reputation: 31
In Android, you can not directly click on keypad keys until you use Appium coordinates to perform click/tap action which is not always reliable. But you can simulate Hardware keys on android using Appium.
To press(simulate) Done button, use the below code:
driver.pressKey(new KeyEvent(AndroidKey.ENTER));
Upvotes: 2
Reputation: 5288
On my Pixel 3, I've automated tapping the Search/Next/Done button using adb via this command:
adb shell input tap 1070 1940
The x,y coordinates will vary based on your device. The get a rough sense of where to start, you can use adb to determine your screen size, and then move in and up from the lower-right corner. So, on my Pixel 3, I used this adb command to determine window size:
adb shell wm size
That gave me this output: "Physical size: 1080x2160". I moved ten pixels in from the right and 180 up from the bottom to get the "1070 1940" x,y coordinates that work for me.
So now I can enter a search string into a text field and emulate tapping the search key on the soft keyboard with something like this:
adb shell input text searchterm && adb shell input tap 1070 1940
This is all necessary because the search box I'm using is an Android EditText with this XML attribute to indicate that the standard Enter key should be replaced with a search icon:
android:imeOptions="actionSearch"
If that weren't the case, I believe I could just send the standard KeyEvent for the Enter key:
adb shell input keyevent 66
With the IME search option enabled, I believe you would have to send KeyEvent.KEYCODE_ENTER (i.e., 66) along with FLAG_EDITOR_ACTION (which has a mask value of 16), but it does not appear that adb shell input supports the addition of flags.
I've tried sending KEYCODE_SEARCH (i.e., 84), which has been present in the Android API since version 1, but that doesn't work on the application I'm testing. Not sure why.
Upvotes: 0
Reputation: 4638
Looks like there is no constructive way to click on the Done or Next button on the device keyboard. So as a temporary solution I'm tapping with 2 fingers on the Done button coordinates, However this is not a viable solution to do this. Will wait until appium comes with fix for this in next version.
Upvotes: 1