How to press ENTER keyboard when search data on mobile apps

what key is used to press ENTER key when searching data in mobile application?

I’ve used this code but it does not work
Mobile.sendKeys(findTestObject(``'TestObject'``), Keys.chord(Keys.ENTER``))
and it doesn’t work too
Mobile.sendKeys(``'Katalon Studio'``)

I have the same problem too.
Please someone check this issue

Maybe you could try clicking the test object first? I know sendKeys should be enough, but this workaround (first click the object, than pres ENTER) worked for me before.

Hi Mate

I sendKeys successfully but then can’t perform enter action i use this code please see the code and tell me if i make mistake somewhere : Mobile.sendKeys(findTestObject(‘SearchBox’), Keys.chord(Keys.RETURN))

Thanks

Did you get any error messages? Also, did you remember to import Keys:

   import org.openqa.selenium.Keys as Keys

Yes i have imported this and there is no error message the test is pass but when i look at the test i see that this command sends something invalid characters (like envelope).
I am doing this before perform enter and it’s working:

Mobile.tap(findTestObject(‘Object Repository/Variables/SearchBox Guitar Center’), 2)

Mobile.setText(findTestObject(‘Object Repository/SearchBox’), ‘guitar’, 0)

I solved this issue with sendKeys : ‘guitar’+’\\n’

5 Likes

hi,
use Mobile.tapAtPosition(1075, 1900, FailureHandling.OPTIONAL)

try it,

You can use the AppiumDriver and AndroidKeyCode enum to access any keys on the Android keyboard:

import io.appium.java_client.android.AndroidDriver
import io.appium.java_client.android.AndroidKeyCode

AndroidDriver<?> driver = MobileDriverFactory.getDriver()
driver.pressKeyCode(AndroidKeyCode.ENTER)

i’ve try this, but i got this error @Chris_Trevarthen

Reason:

groovy.lang.MissingPropertyException: No such property: AndroidKeyCode for class: Script1550041516587

Hi @Zulfikar_Mulyakusuma,

Try adding these import statements at the top of your test file, which should give you access to the AndroidKeyCode class:

import io.appium.java_client.android.AndroidDriver
import io.appium.java_client.android.AndroidKeyCode

Hope this helps,

Chris

Hi @Chris_Trevarthen,

I’ve try to import this statements

and this code

but the results are like this

it looks like the code isn’t executed correctly. And the pressKeyCode command does not appear in suggestion. is there another way?

Best regards,
Zulfikar

Hi @Zulfikar_Mulyakusuma,

I did just see that pressKeyCode is deprecated in newer versions of Appium. Could you tell me which version of Appium you’re using? Katalon Studio 5.10.x only supports Appium 1.8.1 (or 1.8.2-beta).

You could also try switching the pressKeyCode line with:

driver.pressKey(new KeyEvent(AndroidKey.SEARCH))

You’ll need to add the imports for:

import io.appium.java_client.android.nativekey.AndroidKey
import io.appium.java_client.android.nativekey.KeyEvent

Hope this helps,

Chris

Hi @Chris_Trevarthen,

I use Appium 1.8.1 and use Katalon Studio 5.10.1

Best Regards,
Zulfikar

Thanks @Zulfikar_Mulyakusuma, those should be the correctly supported versions.

When I run that pressKeyCode on my test, I see the same thing that you see where it looks like it’s not running, but in my case it actually does execute.

Some other things you could try if it doesn’t seem to work:

  1. Make sure the keyboard is actually open when you try to call pressKeyCode. You might need to have the test tap on the text field first to be sure.
  2. Try a different KeyCode other than SEARCH. There are whole bunch, including ENTER, which seems like a generic one that could work.

Hope this helps,

Chris

I am facing the same issue with the search key for Samsung keyboard.
Any solution would be appreciated.

Thanks,
Dhaval

Am also not able to run that both test cases.

AndroidDriver<?> driver = MobileDriverFactory.getDriver()
driver.pressKey(new KeyEvent(AndroidKey.ENTER))

It is underlined under pressKey.

But the rest of my test cases has executed. Please help me with this. @Chris_Trevarthen

Hi @mchidambarakumar,

Could you please let me know what version of Katalon Studio, Appium, and Android you’re testing on?

(I do see the underline for pressKey myself, but I don’t think it’s an issue - I think it has to do with the way that the AndroidDriver is being used with a generic type. If the pressKey function was truly not available, you should see a crash when running the test.)

– Chris

Hi @Chris_Trevarthen

I am using setText method for the search in Android and using mobile.hidekeyboard() just as an enter purpose.

but can’t see the update results based on the search as keyboard is not getting opened here.

Could you please help me here?

Hi @QA21,

Something that might work better for you would be to tap the field that you’re trying to enter text into. Then use the sendKeys() function instead of setText(). Here’s some info on how to use it:

Hope this helps,

Chris