Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android - pressKeyCode not working #257

Closed
aohrem opened this issue Oct 14, 2015 · 10 comments

Comments

@aohrem
Copy link

commented Oct 14, 2015

The pressKeyCode() method of the AndroidDriver is not working for me and apparently a lot of other users from different help desks at the web as well. Example: https://discuss.appium.io/t/unable-to-tap-search-button-on-android-softkeyboard/1598

Appium java-client version 3.2

@TikhomirovSergey

This comment has been minimized.

Copy link
Member

commented Oct 14, 2015

Hi @aohrem
It is definitely the server-side problem, I think.

There are too many concerns and opinions in mentioned topic. Let's talk about your problem. What does happen? Is some exception thrown?

Please provide stacktrace and server output as attached gists.

Is this issue suitable for your case?
appium/appium#5162

@aohrem

This comment has been minimized.

Copy link
Author

commented Oct 15, 2015

So, I also try to press the search button of the soft keyboard to start a location search in a native Android app. I tried the following things to achieve that:

mDriver is of the type AndroidDriver.

  • mDriver.pressKeyCode(66);
  • mDriver.pressKeyCode(84);
  • mDriver.pressKeyCode(AndroidKeyCode.ENTER); // should be 66
  • mDriver.pressKeyCode(AndroidKeyCode.KEYCODE_SEARCH); // should be 84
  • mDriver.pressKeyCode(AndroidKeyCode.KEYCODE_ENTER); // should be 66

Also, I tried some work-arounds:

  • clicking the search button coordinates with mDriver.tap() (screen width - X, screen height - X)
  • sending a "\n" to the search field and the end of the search string with the sendKeys() method of my search field WebElement
  • The mDriver.sendKeyEvent() method does not exist.

None of the above-mentioned solutions worked, but I also got no Exception or error message. The test just continues without the search button beeing pressed, so I assumed there has to be a bug in the Appium code.

The issue from your link (#5162) seems very related, but as far as I can see, I tried all solutions mentioned in that thread and none of those worked.

@TikhomirovSergey

This comment has been minimized.

Copy link
Member

commented Oct 15, 2015

@aohrem
Ok. Now it is clear
I think you'll face this issue the root cause appium/appium#5162 is found. It is most likely on the the server side and it is probably won't be fixed by the java_client code changing.

Right now I can't mention one more workaround. Maybe @Jonahss or @bootstraponline know more.

It woild be great if you attached two gists to this issue. A one with your java code sample and another with server output.

One more question. Which Appium server version do you use?

@aohrem

This comment has been minimized.

Copy link
Author

commented Oct 15, 2015

Thank you, this really helped. :) I actually used an older Appium server version (1.4.0.0) and now updated to 1.4.13.1. Now this command works: mDriver.pressKeyCode(AndroidKeyCode.KEYCODE_ENTER);

@aohrem aohrem closed this Oct 15, 2015

@TikhomirovSergey

This comment has been minimized.

Copy link
Member

commented Oct 15, 2015

Ok @aohrem . I'm happy :)

@xiaominghou

This comment has been minimized.

Copy link

commented Mar 24, 2016

hi I have use:
capabilities.setCapability("unicodeKeyboard", "True");
capabilities.setCapability("resetKeyboard", "True");
To let me input Chinese word , and the keyboard is disappeared. So ,i cannot get the coodi for the search button, how can I to click the search button?

@abvijay

This comment has been minimized.

Copy link

commented Oct 12, 2016

I dont see SendKeyEvent or pressKeyCode in appiumdriver instance. Using AppiumForWindows 1_4_13_1.
I need to delete Default value in the Email Field(Textbox) and Enter new value.

@RanjithHS

This comment has been minimized.

Copy link

commented Mar 2, 2017

pressKeyCode is not working for me even after using java client 5.0
please let me know if someone has implemented the same.
Appium version 1.5.3

@gitterchris

This comment has been minimized.

Copy link

commented Oct 31, 2017

Do you have any workaround for this? Keycode 66 works but not 84.

@jarod-legault

This comment has been minimized.

Copy link

commented May 16, 2019

This solution in JavaScript worked for me:

return driver.waitForElementById(<elementId>).type(<text to type>).click().execute( "mobile: performEditorAction", { "action": "search" } );

This allowed me to find a text field, input some text, and submit a search command (same as clicking the search icon in the keyboard). Of course, you have to replace <elementId> and <text to type> with the proper values. See http://appium.io/docs/en/commands/mobile-command/ for details on "mobile: performEditorAction".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.