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:
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.
HashMap<String, Integer> swipeObject = new HashMap<String, Integer>();
swipeObject.put(“keycode”, 84);
((JavascriptExecutor ) driver).executeScript(“mobile: keyevent”, swipeObject);
Appium says not yet implemented.
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.
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?
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).
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).
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.
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.
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.