How to press ENTER keyboard when search data on mobile apps

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

Hi @Chris_Trevarthen Thank You.

Have tried the above solution but actually the issue is post entering the text I am using Mobile.hidekeyboard() but its not working as an enter. So I think here have to use some keyboard enter event just to get the search result.

I have used the driver = MobileDriverFactory.getDriver()
driver.pressKey(new KeyEvent(AndroidKey.ENTER)) but looks like the PressKey is deprecated.

Hi @QA21,

You’re right, I don’t think the Mobile.hideKeyboard() function is guaranteed to send a return/enter key. I think that pressKey is still ok, but pressKeyCode is deprecated per the Appium docs:

https://appium.github.io/java-client/index.html?io/appium/java_client/android/nativekey/PressesKey.html

If pressKey is working for you, I would say to keep using it. If it’s not, let’s troubleshoot further.

– Chris

Hi @Chris_Trevarthen tried so many ways but still struggling with the above.
Could you pleas help me out?

Hi @QA21,

If none of the above options work for you, you can try using the tapAtPosition function, tapping at the coordinates where the enter button will be. You should be able to calculate this based on your screen size:

https://docs.katalon.com/katalon-studio/docs/mobile-tap-at-position.html

Hope this helps,

Chris

1 Like

It worked for me, thanks @Goran

1 Like

Hello Everyone, If you still didn’t get any solution regarding this, then try this. It’s works for me.

First Import

    import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory as MobileDriverFactory
    import io.appium.java_client.android.AndroidDriver as AndroidDriver
    import org.openqa.selenium.Keys as Keys
    import com.kms.katalon.core.logging.KeywordLogger
    import com.google.common.collect.ImmutableMap as ImmutableMap;

Then called AndroidDriver

AndroidDriver<?> driver = MobileDriverFactory.getDriver()

Now select that Text field by spying/recording/from captured object class name and send your desired text:

driver.findElement(By.className('android.widget.EditText')).click()
Mobile.delay(3)
driver.getKeyboard().sendKeys("milk")

Now Click on search by writing this command

driver.executeScript("mobile: performEditorAction", ImmutableMap.of("action", "search"));

4 Likes