How to handle native android keyboard using appium

Hello ,
I am working on app in which i need click on Done button of native android keyboard. But i am unable to click on that

Scenario would be like::

  1. Launch application
  2. click on search bar
  3. Type some text
  4. click on done button of native android keyboard.

Any help in this?

Currently there is one way to do so is sending the key event of the ā€œEnterā€ key.
You cant get the android keys as element because UI Automator does not detects the buttons of the keyboard.

One Work Around to do exactly what you mentioned is presize tap on the ā€œDoneā€ button, but it wonā€™t be generic.(Avoid it)
Using the key event is the best and recommended way.

Can you check whether button can be pressed using adb command manually?

adb -s input keyevent 84

if that command performs action then appium should work. otherwise issue is something else

Thanks,
Priyank Shah

How can we use the keyevent to type search button. Can you please provide the java appium code

Please help me to enter search button after entering text in a search box of an android application.

Sorry for the late response(turned of the notification for this post by mistake)
Hereā€™s the snippet iā€™m using

String command = "adb shell input text \""+newData+"\"";
Process result = Runtime.getRuntime().exec(command);

You can mix and mach these commands whatever fulfills your requirements.

@Priyank_Shah I donā€™t use the integer values i.e. 84 you used. I always pass the string constant android site provided.

adb -s input keyevent KEYCODE_SEARCH

and the key event for the buttons other than the characters donā€™t work always.
I prefer

element.sendKeys(text+"\n")
1 Like

@pr4bh4sh, why not using dirver.keyevent(84) for KEYCODE_SEARCH. I think itā€™s very simple way.
WRT ā€œDoneā€ or ā€œOKā€ key, I donā€™t see any android keyevents for it link
which really amazes me

Indeed thatā€™s the simplest way.( What i suggested were workaround as the author of this post was looking for the possible way to actually tap on the key, which is not possible for android)

Yes there arenā€™t any Key code for ā€œDoneā€, to achieve this i usually send enterā€™s key code

Thanks for pointing it out.(Updated the answer.)

you mean this one:

public static final int KEYCODE_ENTER

Key code constant: Enter key. Value: 66 (0x00000042)

Is it equal to ā€œDoneā€/ā€œOKā€ keys on software keyboard?

No there arenā€™t any specific key code for Done/OK/Next key. For simulating those we need to send the metastate along with the keycode of ā€œEnterā€ key.

driver.sendKeyEvent(key, metastate);

For sending the Next/Done key metastate code is 16.

If that not working we can send the KEYCODE_DPAD_DOWN (for Next).
And these are just workaround if the thing are not working as expected.

2 Likes

@pr4bh4sh, I got it. Thanks!

@Alex_Bogdanov
Could you please share your code that works? I am facing the same problem. Thanks!

Sorry @Olivia_Ong for so late answer. If it still hasnā€™t solved, could you please explain what actual problem did encounter with key codes?

Any help would be appropriated

I need to click or tap on Go/Done button on android s3 device which running 4.3 version

I tried all sorts of option

  1. driver.pressKeyEvent(66) or driver.pressKeyEvent(AndroidKeyCode.ENTER)
  2. Driver.sendKeyEvent(66)
  3. driver.execute(ā€œmobile:keyeventā€, ā€œkeycode:66ā€);

I manage to click on all keys except Go/Done button

Environments
Appium version - 1.4.13
Java 1.7 appium
Maven - 3.2.0

Can you try sending the key event via adb??

For the Next/Go/Done combination, I use
adb shell input keyevent ā€˜KEYCODE_TABā€™
http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_TAB

Hope this helps

1 Like

Thanks Guys for your reply

I tried on my app it doesā€™t work

But, I tried with other apps which are installed on my device

I used command ā€œadb shell input keyevent KEYCODE_ENTERā€ā€¦ It worked

So problem might to with in my app, may be some key event listners are not implemented i think,

@rakesh Are you using below capability ?
capabilities.setCapability("unicodeKeyboard", true);
If not can you try with this capability.

1 Like

Hi,

capabilities.setCapability(ā€œunicodeKeyboardā€, true) didā€™t worked for me

I asked my developer to add a lister called ā€œOnKeyListenerā€

finally workedā€¦

refer to this Unable to tap 'search' button on Android softKeyboard
@praveentp009 explained in detail

thanks @praveen

hello rakesh,
please send me your test script