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

Unable to tap search button in Android App keyboard using automation #5162

Closed
karunakaranvrv opened this issue May 26, 2015 · 24 comments
Closed
Labels
Android related to Android-native driver(s)

Comments

@karunakaranvrv
Copy link

@jlipps @imurchie

Steps:-

  1. Entering text on the search text field
  2. Tap the search button on Android keyboard(In Android App)

Code to tap on search button:-

Method1:-

driver.sendKeyEvent(0x00000054);

Where 0x00000054 is KEYCODE_SEARCH. Refer http://developer.android.com/reference/android/view/KeyEvent.html

Method2:-

driver.sendKeyEvent(84). where 84 is constant value for search.

Refer:-
public static final int KEYCODE_SEARCH

Added in API level 1
Key code constant: Search key.

Constant Value: 84 (0x00000054)

What keycode I have to pass to make it work?
Kindly help me.

@triager triager added the Needs Triage bugs which are not yet confirmed label May 26, 2015
@imurchie
Copy link
Contributor

imurchie commented Jun 1, 2015

Can you send 66? That is KEYCODE_ENTER, which will submit the form.

@sebv sebv added OnGoing and removed Needs Triage bugs which are not yet confirmed labels Jun 3, 2015
@karunakaranvrv
Copy link
Author

@imurchie I have tried 66, but its doesn't work for me.

@imurchie
Copy link
Contributor

imurchie commented Jun 6, 2015

Ok. Can you give us the Appium server logs? So we can see what, if anything, is going on?

@karunakaranvrv
Copy link
Author

@imurchie
I have tried using 0x00000054 and 66 in sendKeyEvent and appium logs are listed below:-

=> 0x00000054

driver.sendKeyEvent(0x00000054);

Appium logs:-

info: --> POST /wd/hub/session/b4bc70c1-bcb8-4bc1-8f3f-41dd953b844d/element/3/value {"id":"3","value":["Mumbai"]}
info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"3","text":"Mumbai","replace":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"3","text":"Mumbai","replace":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: setText
info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().
info: [debug] [BOOTSTRAP] [debug] Text remains after clearing, but it appears to be hint text.
info: [debug] [BOOTSTRAP] [debug] Text not cleared. Assuming remainder is hint text.
info: [debug] [BOOTSTRAP] [debug] Sending plain text to element: Mumbai
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"b4bc70c1-bcb8-4bc1-8f3f-41dd953b844d"}
info: <-- POST /wd/hub/session/b4bc70c1-bcb8-4bc1-8f3f-41dd953b844d/element/3/value 200 7225.980 ms - 76 {"status":0,"value":true,"sessionId":"b4bc70c1-bcb8-4bc1-8f3f-41dd953b844d"}
info: --> POST /wd/hub/session/b4bc70c1-bcb8-4bc1-8f3f-41dd953b844d/appium/device/keyevent {"keycode":84}
info: [debug] Pushing command to appium work queue: ["pressKeyCode",{"keycode":84,"metastate":null}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"pressKeyCode","params":{"keycode":84,"metastate":null}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: pressKeyCode
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"b4bc70c1-bcb8-4bc1-8f3f-41dd953b844d"}
info: <-- POST /wd/hub/session/b4bc70c1-bcb8-4bc1-8f3f-41dd953b844d/appium/device/keyevent 200 104.365 ms - 76 {"status":0,"value":true,"sessionId":"b4bc70c1-bcb8-4bc1-8f3f-41dd953b844d"}
info: --> DELETE /wd/hub/session/b4bc70c1-bcb8-4bc1-8f3f-41dd953b844d {}
info: Shutting down appium session

=> 66

driver.sendKeyEvent(66);

Appium logs:-

info: <-- POST /wd/hub/session/dee8cd13-e647-4300-8498-f5dc2bf1c7d1/element 200 42.612 ms - 87 {"status":0,"value":{"ELEMENT":"3"},"sessionId":"dee8cd13-e647-4300-8498-f5dc2bf1c7d1"}
info: --> POST /wd/hub/session/dee8cd13-e647-4300-8498-f5dc2bf1c7d1/element/3/value {"id":"3","value":["Mumbai"]}
info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"3","text":"Mumbai","replace":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"3","text":"Mumbai","replace":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: setText
info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().
info: [debug] [BOOTSTRAP] [debug] Text remains after clearing, but it appears to be hint text.
info: [debug] [BOOTSTRAP] [debug] Text not cleared. Assuming remainder is hint text.
info: [debug] [BOOTSTRAP] [debug] Sending plain text to element: Mumbai
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"dee8cd13-e647-4300-8498-f5dc2bf1c7d1"}
info: <-- POST /wd/hub/session/dee8cd13-e647-4300-8498-f5dc2bf1c7d1/element/3/value 200 7551.528 ms - 76 {"status":0,"value":true,"sessionId":"dee8cd13-e647-4300-8498-f5dc2bf1c7d1"}
info: --> POST /wd/hub/session/dee8cd13-e647-4300-8498-f5dc2bf1c7d1/appium/device/keyevent {"keycode":66}
info: [debug] Pushing command to appium work queue: ["pressKeyCode",{"keycode":66,"metastate":null}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"pressKeyCode","params":{"keycode":66,"metastate":null}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: pressKeyCode
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"dee8cd13-e647-4300-8498-f5dc2bf1c7d1"}
info: <-- POST /wd/hub/session/dee8cd13-e647-4300-8498-f5dc2bf1c7d1/appium/device/keyevent 200 51.426 ms - 76 {"status":0,"value":true,"sessionId":"dee8cd13-e647-4300-8498-f5dc2bf1c7d1"}
info: --> DELETE /wd/hub/session/dee8cd13-e647-4300-8498-f5dc2bf1c7d1 {}
info: Shutting down appium session

@imurchie
Copy link
Contributor

imurchie commented Jun 8, 2015

Ok. The keyevent is getting through in both cases. I guess it's just a matter of finding the correct key event. Without the app, it is hard to say from here.

@sebv
Copy link
Member

sebv commented Jun 16, 2015

Any progress?

@sebv sebv added NoActivity Android related to Android-native driver(s) and removed NoActivity labels Jun 16, 2015
@karunakaranvrv
Copy link
Author

@imurchie @sebv
searchbutton

Here i have attached screen shot for search button.

  1. I can able to create enter a city name in search field
  2. When i click on search button using android key-event, no action on performed.

@sebv sebv added OnGoing and removed NoActivity labels Jun 17, 2015
@moizjv
Copy link
Member

moizjv commented Jun 20, 2015

Is this keyboard different? adb shell ime list should list all enabled imes

@ShruthiSudhanva
Copy link

Hi,

We are facing the same issue automating testing on our app using appium. The logs for the keyEvents 84 and 66 are similar to the outputs listed in the above comments. Here is what we have listed for
>adb shell ime list
com.google.android.googlequicksearchbox/com.google.android.voicesearch.ime.VoiceInputMethodService:
mId=com.google.android.googlequicksearchbox/com.google.android.voicesearch.ime.VoiceInputMehodService mSettingsActivityName=com.google.android.voicesearch.ime.ImePreferences
mIsDefaultResId=0x0
Service:
priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false
ServiceInfo:
name=com.google.android.voicesearch.ime.VoiceInputMethodService
packageName=com.google.android.googlequicksearchbox
labelRes=0x7f0b08d8 nonLocalizedLabel=null icon=0x0 banner=0x0
enabled=true exported=true processName=com.google.android.googlequicksearc
hbox:search
permission=android.permission.BIND_INPUT_METHOD
flags=0x0
com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME:
mId=com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIM
E mSettingsActivityName=com.android.inputmethod.latin.settings.SettingsActivity
mIsDefaultResId=0x7f0b0000
Service:
priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false
ServiceInfo:
name=com.android.inputmethod.latin.LatinIME
packageName=com.google.android.inputmethod.latin
labelRes=0x7f08005b nonLocalizedLabel=null icon=0x0 banner=0x0
enabled=true exported=true processName=com.google.android.inputmethod.latin
permission=android.permission.BIND_INPUT_METHOD
flags=0x0

Any help related to this would be extremely useful. Thanks in advance!

@email2vimalraj
Copy link

I'm also facing this issue. But I was debugging the code written by the developer which looks like as follows:

@OnEditorAction(R.id.etSearchView)
protected boolean onSearchClicked(int actionId) {
    if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_SEARCH || actionId == KeyEvent.KEYCODE_ENTER) {
        // Do search   
    }
}

It never hit the KeyEvent.KEYCODE_ENTER, rather it hits EditorInfo.IME_ACTION_SEARCH. Hence the actionId is always 3. This is why we are not able to listen to the KEYCODE_ENTER which is 66. We should have some listener to the EditorInfo actions.

@clmathuriya
Copy link

clmathuriya commented Oct 10, 2016

@email2vimalraj are you able to perform EditorInfo. IME_Actions ?
I am also facing the same issue.

Our developers using IME_ACTION_SEND which has constant value 4.

When trying to perform this action with appium keypress its performing BACK.

driver.pressKeyCode(4);// IME_ACTION_SEND

has anyone found a way to perform EditorInfo IME actions using appium ?

@Vishnu-Rathore
Copy link

If you wanna perform Search on the Native Search App then you can use - AndroidKeyCode
driver.longPressKeyCode(AndroidKeyCode.KEYCODE_SEARCH);

But I'm still trying to find out how to actually Tap on the Android Keyboard Search Icon

@magnumrocha
Copy link

Hi guys, I'm facing the same problem.

Sending a "UiDevice.getInstance(getInstrumentation()).pressSearch()" or "UiDevice.getInstance(getInstrumentation()).pressKeyCode(KeyEvent.KEYCODE_SEARCH)", nothing happens :-(

But, when a send a "UiDevice.getInstance(getInstrumentation()).pressEnter()", the actionId sent in onEditorAction(int actionId) method is 0 (zero). For now, this was the only way I could do to get my EditText "onEditorAction" method fired.

Any solution for this case ??

@jlipps
Copy link
Member

jlipps commented Jan 17, 2017

@magnumrocha those don't look like Appium commands, they look like UiAutomator commands. In any case without the app or a recent set of Appium logs run on Appium's UiAutomator2 backend, this will be impossible to track down. Closing for now.

@jlipps jlipps closed this as completed Jan 17, 2017
@Suban5
Copy link

Suban5 commented Jul 6, 2018

This commands solves my problem
((AndroidDriver<MobileElement>) driver).pressKey(new KeyEvent(AndroidKey.ENTER)

@varundotm
Copy link

varundotm commented Jan 29, 2019

Hi guys, I'm facing same issue,

Can anyone suggest KeyEvent code for IME_ACTION_DONE button or how to handle IME_ACTION_DONE button click??
@Suban5 I have tried your solution, my case its not working
@jlipps please reopen the issue

@mykola-mokhnach
Copy link
Collaborator

@varundotm https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/android-ime.md

@varundotm
Copy link

@mykola-mokhnach thanks , its working for me

@jarod-legault
Copy link

This solution worked for me in JavaScript:

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".

@ChandraSharma0377
Copy link

Try below java script code.
driver.executeScript("mobile: performEditorAction", ImmutableMap.of("action", "search"));

action: The name or an integer code of the editor action to be executed. The following action names are supported: normal, unspecified, none, go, search, send, next, done, previous

@RRohitmehta
Copy link

Try below java script code.
driver.executeScript("mobile: performEditorAction", ImmutableMap.of("action", "search"));

action: The name or an integer code of the editor action to be executed. The following action names are supported: normal, unspecified, none, go, search, send, next, done, previous

Thanks, @ChandraSharma0377 , This javascript code worked for me as well.

@Mmallineni
Copy link

@ChandraSharma0377 @RRohitmehta does the javascript code works with Action Class ?

@Mmallineni
Copy link

This worked Thanks @ChandraSharma0377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android related to Android-native driver(s)
Projects
None yet
Development

No branches or pull requests