Android: Press Done Button On Keyboard
Solution 1:
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(newKeyEvent(AndroidKey.ENTER));
Solution 2:
On my Pixel 3, I've automated tapping the Search/Next/Done button using adb via this command:
adbshellinputtap1070 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 10701940
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.
Solution 3:
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
Post a Comment for "Android: Press Done Button On Keyboard"