Java-client: Key Event 'KEYCODE_SEARCH' doesn't work (do nothing)

Created on 28 May 2018  路  6Comments  路  Source: appium/java-client

Description

Hello,

Key Event 'KEYCODE_SEARCH' doesn't work (do nothing)

AndroidDriver dr;
dr.sendKeyEvent(AndroidKeyCode.KEYCODE_SEARCH);

I test it with a click on google search on android home, and after type toto.

Environment

  • java client build version or git revision if you use some shapshot: 5.0.4
  • Appium server version or git revision if you use some shapshot: 1.8.1
  • Desktop OS/version used to run Appium if necessary: Ubuntu
  • Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe:
  • Mobile platform/version under test: Android 6
  • Real device or emulator/simulator: Real device

Details

I test with a keypress with adb :
```
adb shell input keyevent KEYCODE_SEARCH
````
I have the same problem. So, perhaps it's because of adb ?...

Most helpful comment

This solution in JavaScript using wd 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".

All 6 comments

Try

   pressKey(new KeyEvent(AndroidKey.ENTER)
                .withFlag(KeyEventFlag.SOFT_KEYBOARD)
                .withFlag(KeyEventFlag.KEEP_TOUCH_MODE)
                .withFlag(KeyEventFlag.EDITOR_ACTION));

This snippet works with java client 6.0.0-stable and the UIAutomator2 bundled with Appium 1.8.1+

Hi @mykola-mokhnach,

This workaround works, but it's really the same as a SEARCH keyevent ?

It should be. This snippet simulates sending IME action and Espresso, for example, does the same trick.

@mykola-mokhnach is there a Webdriverio solution for this as well because it currently does nothing with Webdriverio

This solution in JavaScript using wd 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".

@jarod-legault Awesome

Was this page helpful?
0 / 5 - 0 ratings