Unable to tap 'search' button on Android softKeyboard

Hello,

I am trying to type in a search box within my app and tap/click on search button(magnifying glass) on keyboard. But I am unable to click/tap on it. I have tried below things:

  1. driver.sendKeyEvent(84);
    Appium says it successfully sent in the command but ‘search’ does not get tapped. Cursor remains in text box and results do not filter.

  2. HashMap<String, Integer> swipeObject = new HashMap<String, Integer>();
    swipeObject.put(“keycode”, 84);
    ((JavascriptExecutor ) driver).executeScript(“mobile: keyevent”, swipeObject);
    Appium says not yet implemented.

  3. JavascriptExecutor jse = (JavascriptExecutor) driver1; jse.executeScript(“UIATarget.localTarget().frontMostApp().keyboard().buttons()[‘Done’].tap();”);
    Appium says not yet implemented.

  4. driver.sendKeyEvent(AndroidKeyCode.ENTER, AndroidKeyMetastate.META_FUNCTION_ON);
    Appium says it successfully sent in the command but ‘search’ does not get tapped. Cursor remains in text box and results do not filter.

  5. driver.sendKeyEvent(AndroidKeyCode.ENTER);
    Nothing happens

All other send key events works except ENTER, Search. I can use sendKeyEvent for alphabets, numbers, space etc.

I am using Ecllipse, AndroidDriver, AppiumDriver, TestNG, Appium(1.2.4.1), Samsung Galaxy Note 3.

Any help on this would be really helpful. I went through lot of Googling but till not successful tapping search key.

I’m not sure about it, however I read the article wrote by a guy from Yandex and they’ve mentioned that they handled similar problem with tapping into coordinates. So you just need to calculate the coordinates of your magnifying glass and tap there. Hope it will help

I already did that and that works. Thank you.
But now that does not work when I change devices. The search button co-ordinates change for different screen size. Any work around?

Is there a chance to calculate coordinates from scree size? I mean like have a button coordinates as a i.e. screen height * 0.23 and screen width * 0.35?

Yes I guess that an be done. But it would be great if Appium starts sending in ‘SEARCH’ key soon. :smile:

Thanks for the help once again.

any updates on this ?

Please help me to enter search button after entering some text on search field in Android application

Hi,

Please use Android Drivers to tap on Search button co-ordinates.

driver.tap(1, 710, 1260, 1);

Here 710, 1260 are co-ordinates lying on my Search button. Change them to your required co-ordinates to tap on Search.

As of now I am tapping on Search by co-ordinates. Still not able to use sendkeycode()

driver.tap(1, 710, 1260, 1);

Hi,

use this option to click Soft keyboard search key icon

driver.sendKeyEvent(66);

1 Like

Is that one working with the ‘search’ key?
I have another workaround if you do not want to tap a xy-location (like me, because I use different devices/sims).

I have a step: I set (.) as value on the (.) (.*) — (value, id, type)
I always save the value in the World object in the property lastValue (so I overwrite it every time I use this step).
And I always save the id in the World object in the property lastId (so I overwrite it every time I use this step).

this.driver
.waitForElementById(id, this.TIME_OUT, this.POLLING_TIME)
.setText(value)
.nodeify(next);

Then I have step: I send key event (.*) — (code)
I check if its the code for the search button. If it is then I set the value again but with an enter behind the value. It cost you a bit more time but you probably don’t use the search key event a lot (because often there is a physical button).

this.driver
.waitForElementById(this.lastId, this.TIME_OUT, this.POLLING_TIME)
.setText(this.lastValue+’\n’)
.nodeify(next);

Hi!

The problem is still actual in appium 1.4 and it’s rather citical for us. We want to run out tests on different devices but we need to use coordinates because of this issue and it’s problem. We hoped that this issue would be fixed in 1.4 but it doesn’t.

1 Like

We have faced the same issue during our test script creation and resolved it successfully.
Initially when we create the script we used " driver.sendKeyEvent(66)" and even tried 84 for clicking on search button but it never worked.
Later after doing research we identified the below details,

In the application source when user tap on the search it is used “OnEditorActionListener” to identify the search key pressed and do action based on it, The function definition looks like below
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
– the condition and the action written inside this–
}

Unfortunately the keyevent we are sending will not capture through this listener, So we have added another listener and method to handle that case along with OnEditorActionListener , that is “OnKeyListener” and the method definition looks like below
public boolean onKey(View v, int keyCode, KeyEvent event)
{
– The condition to check for keycode 66 and 84 and if it is satisfied do the search action—
}
This will be used when we send the keyevent from the script and there is no impact on the manual search process.After this the search is working very fine without any issue.

Please note; we havent changed anything in our test script, only change made in the application soruce for search part.

You can check with your app developer to check this case.I hope this will help to resolve the issue.

2 Likes

Hello…you have said that you used coordinates to tap on search ,can you please tell me how exactly you did it??

Hi! we just found in Android Device Monitor the approximate coordinates of the search button and just tap on this coordinate with tap action. But as I mentioned before - this works only for exact device with exact screen size.

This is really annoying. I am not sure why Appium team is not taking this as priority issue. For many e-Commerce applications, this is basic functionality by searching for an item.

Tried all above options(except changing listener method specified by praveen) specified in the thread, but none helps.

@preetparikh
Did you try like below,

If your text box xpath is //SearchTextEdit and search term is Hello

driver.findElement(By.xpath("//SearchTextEdit")).sendKeys(“Hello”+"\n");

1 Like

As praveen said, this could be a listener issue.

If the application is having valid listener, then in most of the time “string+”\n"" should work.

But if it doesnt have proper listener, which may not succeed.

In my case, i am not sure what is wrong, but when i tried string+"\n" which navigates me to Home screen.

For now, this is a blocker issue for me.

For me driver.sendKeyEvent(66); is working

I getting an error, The method sendKeyEvent(int) is undefined for the type AndroidDriver,