Can anybody tell me how can i use the keyboard keys while automating the mobile apps?
Need help on urgent basis
On Android, you can interact with the keyboard through:
import the following at the top of your test:
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory import io.appium.java_client.android.AndroidDriver import io.appium.java_client.android.AndroidKeyCode
And then use this code to access the keys:
AndroidDriver<?> driver = MobileDriverFactory.getDriver() driver.pressKeyCode(AndroidKeyCode.ENTER)
Where AndroidKeyCode is an enum with all of the possible key entries, e.g.
use Mobile.tapAtPosition(1075, 1900, FailureHandling.OPTIONAL)
Hi, I am unable to enter anything from soft keyboard in device through automation. I need to enter 4 digit pin by selecting each digit from the device soft keyboard. Can you please let me know how to automate it?
Also, the above code throws error when test case is run.
You can try using ‘adb’ command. Refer here: https://www.raizlabs.com/dev/2017/09/automating-input-events-android/. Basically this adb command can be called directly from either cmd (Windows) or terminal(macOS) and so in your script just create a util served as wrapper to call the command, e.g: http://blogs.sheelapps.com/2013/03/run-system-command-in-groovy.html
I updated the response above to include the
import statements you’ll need in order to use the keyboard. The
AndroidKeyCode class should have all the keys you need to interact with the pin screen:
If you’re still receiving errors, could you please provide a log and screenshot of the error.
Am not getting any errors. The TC is passed but nothing happens. It is not clicking on the numbers. Actually this keyboard is present on the screen by default once we navigate to this screen. Once we tap on numbers, the circle gets highlighted in black. Not sure if this is behaving as a soft keyboard.
You might have better luck by disabling the soft keyboard in Android. You’d do this by setting the
resetKeyboard capabilities to
true. You can do this right before starting the app in your test:
import com.kms.katalon.core.configuration.RunConfiguration RunConfiguration.setMobileDriverPreferencesProperty("unicodeKeyboard", true) RunConfiguration.setMobileDriverPreferencesProperty("resetKeyboard", true)
Hope this helps,
Its me again, so I’m trying to enter numeric digit using the android keypad as well and I able to enter the digits just fine but I need to press the “DONE” button within the android keyboard which will lead to me the next screen. so far I have included these codes and here are my errors and the actual screen shot of the application, please help me resolve this issue.
BTW I have already imported- import io.appium.java_client.android.AndroidKeyCode
The error you’re seeing is similar to the error you saw before with
startY: you are repeating the:
AndroidDriver<?> driver = MobileDriverFactory.getDriver()
line, which is unnecessary. That line sets up the
driver variable, and once it’s done one time in your test, you don’t need to do it again, you can just use:
I tried commenting out that line and running the “driver.pressKeyCode(AndroidKeyCode.ENTER)” code and it doesn’t press the enter button within the numeric android keyboard, Actually there isn’t any enter button within the keyboard its called DONE button, can you please help?
I wonder if
AndroidKeyCode.KEYCODE_NUMPAD_ENTER would work in this case since it’s more specifically for a number pad.
Unfortunately AndroidKeyCode.KEYCODE_NUMPAD_ENTER code didn’t work, it executes successfully but doesn’t tap on the Done button within the keyboard at all.
That’s unfortunate that the keys aren’t working for you. Have you been able to use the Spy Mobile tool and try to capture the object for that key? That might give some hint as to what type of element it is.
The alternative, if we can’t get the key to work, is to use
Mobile.tapAtPosition to just tap the screen at a certain coordinate that you know will be within the Done button:
Hope this helps,
If the the “Done” button of the keyboard is at the very bottom right corner of the screen how can I predict the x and y coordination for this button. I’m asking you this is because my native keyboard can not be recognized by the katalon studio spy, that’s why I’m trying to TapAtPosition method.
Assuming that the Done button will always be in the lower right of the screen, you could find the height and width of the screen and then use that to calculate an approximate location of the button:
def height = Mobile.getDeviceHeight() def width = Mobile.getDeviceWidth() def buttonX = height - 30 // this is a guess and assumes that x=0 is at the left of the screen - needs to be played with def buttonY = width - 30 // this is a guess and assumes that y=0 is at the top of the screen - needs to be played with Mobile.tapAtPosition(buttonX, buttonY)
Hope this helps,
Unable to use the android key code. As I searched in website, it has mentioned that Android keycode deprecated. Please provide the solution for this.
It looks like the replacement for
You should be able to use
AndroidKey.ENTER as the enter key.
Hope this helps,
Thanks it worked in me.