This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
21 / 43
Feb 2016

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?

  • created

    Dec '14
  • last reply

    Nov '18
  • 42

    replies

  • 39.7k

    views

  • 27

    users

  • 7

    likes

  • 5

    links

Frequent Posters

There are 42 replies with an estimated read time of 3 minutes.

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

1 month later

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 month later

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 months later
1 month later

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?

3 months later

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

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 month later
2 months later

Except what rakesh said in the above thread(as i cannot force developer to write extra code and developers are not accessible for me)

I tried all the ways specified in this thread, but didnt help. Can someone help me here?

element.sendKeys(strValue+"\n"); - entering the value but soon after navigating to home screen.

element.sendKeys(strValue);
String command = "adb -s input keyevent KEYCODE_SEARCH";
** try {**
** Process result = Runtime.getRuntime().exec(command);**
** } catch (IOException e) {**
** // TODO Auto-generated catch block**
** e.printStackTrace();**
** }**
enter the value but didnt click on Search button.

element.sendKeys(strValue);
driver.sendKeyEvent(AndroidKeyCode.ENTER);
Enter the value and bringing back to home screen.

Also tried with Keyevent codes 84 and 66, but didnt help.

Can someone let me know any other soluctions

Hi UD

i tried all solution nothing worked for me.... i have wasted lots of time trying to find solution without approaching developers, but i did't do any progress ..

my suggestion is ask you develop to add click Listers then it should work

RK

Ohhhhh.... the problem for me is, the app developers are 3rd party vendors and we dont have any access to approach them.

2 months later

@UD the only workaround that I found is to use a third party keyboard (GO Keyboard works for me) and then send key event 66. Works as expected. Maybe if you reverse engineer GO Keyboard implementation you can get more insight on how to make it work without a third party keyboard. Cheers!

19 days later
3 months later

The driver.pressKeyCode(66); method doesn't work for me. The only other solution I have seen is to tap the button based on coordinates. Although it would work it would be awful when trying to support multiple devices.

Has there been any progress on this topic? This feature is fairly critical for the work that I am doing. If anyone has a solution to this it would be greatly appreciated.

26 days later

guys i want to add that Appium driver now has key press code in its API

3 months later

How can we handle enter key on custom numeric keyboard in Android?

3 months later
3 months later

I am using Python 3.6 + Appium V1.6.5
Try the following:

Set the following two lines to your desired_caps.
desired_caps[‘unicodeKeyboard’] = True
desired_caps[‘resetKeyboard’] = True

Then use keycode 66. it works for me.
driver.press_keycode(66)

11 months later

I’m using:
io.appium -> 6.1.0
selenium -> 3.13.0
guava -> 24.0-jre

When I use : ((AndroidDriver)driver).pressKeyCode(67);
I get the following error message with pressKeyCode instruction striked-on : The method pressKeyCode(int) from the type PressesKey is deprecated

With 6.1.0, use this way to press a particular key :
((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.ENTER));

@harshitj :

On using ((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.ENTER));

  1. pressKey gives error:
    The method pressKey(io.appium.java_client.android.nativekey.KeyEvent) in the type PressesKey is not applicable for the arguments (java.awt.event.KeyEvent)
    2 quick fixes available:
    Change to longPressKey()
    Change to pressKeyCode()

  2. (new KeyEvent(AndroidKey.ENTER) gives error: The constructor KeyEvent(AndroidKey) is undefined

  3. KeyEvent is striked.

  4. On changing pressKey to pressKeyCode, I’m getting error: The method pressKeyCode(int) in the type PressesKey is not applicable for the arguments (KeyEvent)

You have included wrong import ‘KeyEvent’.

Remove : import java.awt.event.KeyEvent;

Add these import only :
import io.appium.java_client.android.nativekey.KeyEvent;
import io.appium.java_client.android.nativekey.AndroidKey;

Hi,
I tried with
AndroidDriver driver;
driver.pressKeyCode(66);

It worked for me. Hope it helps you for Android Keyboard Events.
Enter key.
Constant Value: 66

@harshitj, @Sankar_G : Thanks for your inputs.
Presently I have some other business related roadblock, so I’ll update you after some days on what is working.

24 days later
1 month later