Not able to tap on keyboard next/return button on android


#1

I have written custom code to access keyboard

AndroidDriver<?> driver = MobileDriverFactory.getDriver()
driver.getKeyboard().sendKeys(Keys.RETURN)

But its not working.


#2

Should be like this:

driver.pressKeyCode(AndroidKeyCode.BACK);


#3

There is an AndroidKeyCode for the ENTER key as well, so this should work:

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

#4

I am not adept at writing code or able to edit the script. I have a similar issue as above where I need to hit the enter key on the android keyboard but I am not able to when I do the spy mobile. In the manual script view how would I add items or objects so that after entering a name in the search bar the script knows to invoke enter command.

returnkey.jpg


#5

Hi Darlene,

Unfortunately, I don’t know a way to hit the Android Enter button using Test Recorder or Spy Mobile, either.

However, if you want to use the “Manual” view to create and edit your test, you can still add the Enter button handling I mentioned above:

1. Click the down arrow next to “Add” and choose “Binary Statement”
2. This will insert a new row in the test with Item “Binary Statement” and “Input” of “0 == 0”
3. Double click the “0 == 0” value
4. You’ll see a new window with the individual values. Fill in the values like this:

5. Click OK
6. Click the down arrow next to “Add” and choose “Method Call Statement”
7. This will insert a new row in the test with Item “Method Call Statement” and “Input” of “toString()”
8. Double click the “toString()” value
9. You’ll see a new window with the individual values. Fill in the values like this:

10. Click OK
11. You should now see 2 lines in your test like this:

12. Use the Move Up/Move Down buttons to put them in the right order for your test.

This should add Enter button pressing into your Android Katalon test!

Hope this help,

Chris Trevarthen

Screen Shot 2018-08-26 at 11.00.35 PM.png

Screen Shot 2018-08-26 at 11.06.14 PM.png

Screen Shot 2018-08-26 at 11.08.01 PM.png


#6

Ok thank you


#7

Hi,
My application is running, I would like to press on overview button and then close the application. Please do let me know how do I do this, Katalon recoder or Spy mobile is not able to recognised the overview button (square button on next home button).


#8

Hi Chris

I have some problem,
i cant press button ‘SEARCH’ (replace ‘ENTER’) in keyboard mobile test
I try

AppiumDriver<?>driver = MobileDriverFactory.getDriver()
driver.pressKey(new KeyEvent(AndroidKey.SEARCH))
and
AndroidDriver<?> = MobileDriverFactory.getDriver()
driver.pressKeyCode(AndroidKeyCode.KEYCODE_SEARCH)

but not work’s
can you help me sirr,
my katalon ver 6.2.2 appium 1.8.1

regrards
Putra


#9

Hi Cris,

I have same problem
i can’t presskey button ‘SEARCH’ (replace ‘ENTER’) from keyboard on mobile testing
i try use

AndroidDriver<?> driver = MobileDriverFactory.getDriver()
driver.pressKeyCode(AndroidKeyCode.KEYCODE_SEARCH)
and
appiumDriver<?> driver = MobileDriverFactory.getDriver()
driver.pressKey(new KeyEvent(AndroidKey.SEARCH))

but not works
can you help me sirr
btw my katalon ver 6.2.2 and appium ver 1.8.1

regrads
Putra


#10

Hi @Putra.Sinantaka,

You could try a slightly longer version of the pressKey() command:

driver.pressKey(new KeyEvent(AndroidKey.ENTER)
	.withFlag(KeyEventFlag.SOFT_KEYBOARD)
	.withFlag(KeyEventFlag.KEEP_TOUCH_MODE)
	.withFlag(KeyEventFlag.EDITOR_ACTION));

Which was mentioned here:

Hope this helps,

Chris


#11

Hi Chris,

yeah, i have try this, but still not working -___-

AndroidDriver<?> driver = MobileDriverFactory.getDriver()
driver.pressKey(new KeyEvent(AndroidKey.SEARCH)
.withFlag(KeyEventFlag.SOFT_KEYBOARD)
.withFlag(KeyEventFlag.KEEP_TOUCH_MODE)
.withFlag(KeyEventFlag.EDITOR_ACTION))
and
AndroidDriver<?> driver = MobileDriverFactory.getDriver()
driver.pressKey(new KeyEvent(AndroidKey.ENTER)
.withFlag(KeyEventFlag.SOFT_KEYBOARD)
.withFlag(KeyEventFlag.KEEP_TOUCH_MODE)
.withFlag(KeyEventFlag.EDITOR_ACTION))

regrads
Putra


#12

Hi @Chris_Trevarthen,

could you show me step by step to making script for Enter Keys?


#13

Hi @Putra.Sinantaka,

That’s interesting. Could you provide some more info about:

  • What device are you trying to test on?
  • What is the Android version?
  • Is it a real device or emulator?
  • What version of the Android SDK do you have installed on your computer?
  • What version of Katalon Studio are you using?
  • What version of Appium are you using?
  • Are you able to use other keys other than the ENTER key?
  • Could you send a screenshot of your screen when you’re trying to press the ENTER key?

Thanks,

Chris


#14

Hi @khadapynurhuda,

  1. You’ll need to open your test case file in Katalon Studio
  2. Switch to the “Script” tab at the bottom of the window
  3. Add the following import statements to the top of your test file:
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import io.appium.java_client.AppiumDriver
import io.appium.java_client.android.nativekey.AndroidKey
import io.appium.java_client.android.nativekey.KeyEvent
import io.appium.java_client.android.nativekey.KeyEventFlag
  1. In your test, create the steps for tapping on the form field
  2. In your test, create the steps for setting text into the form field
  3. In you test, add the following code to press the enter key:
AppiumDriver<?> driver = MobileDriverFactory.getDriver()
driver.pressKey(new KeyEvent(AndroidKey.ENTER)
	.withFlag(KeyEventFlag.SOFT_KEYBOARD)
	.withFlag(KeyEventFlag.KEEP_TOUCH_MODE)
	.withFlag(KeyEventFlag.EDITOR_ACTION));

Hope this helps,

Chris


#15

Hi @Chris_Trevarthen,

I’ve tried your step by step
But, still, it can’t work

Thank you.


#16

anyway, I’ve used

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

But, I don’t know why, in android keyboard, it will tap on “u”, instead of SEARCH key

Funny, when I tapped “u”, it works to tap on “u”:


#17

Hi @khadapynurhuda,

You could also try using an older function called pressKeyCode:

driver.pressKeyCode(66) // ENTER key

or

driver.pressKeyCode(84) // SEARCH key

Hope this helps,

Chris


#18

Hi Chris,

  • What device are you trying to test on?
    I try to test in tablet, samsung 10.1 inch
  • What is the Android version?
    Android version 9, Pie
  • Is it a real device or emulator?
    Emulator sirr
  • What version of the Android SDK do you have installed on your computer?
  • What version of Katalon Studio are you using?
    My Katalon 6.2.2 version
  • What version of Appium are you using?
    Appium 1.8.1
  • Are you able to use other keys other than the ENTER key?
    yeah, if i press keys other than ENTER its work normality
  • Could you send a screenshot of your screen when you’re trying to press the ENTER key?
    If i try to press ENTER, cursor on application move to next tab

#19

still, it taps on “u”

my Android version is 5.1.1 (KitKat)

is it related to the script that I used?


#20

A few more things you can try if the pressKey functions aren’t working:

Execute an Appium script:

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

Send a newline character into your current text field:

textFieldElement.sendKeys('\n')

Just hide the keyboard:

driver.hideKeyboard()

– Chris