Sendkeys not working properly

Hi all,

I’m doing some automated tests on Android using appium (chrome browser) and i’ve encounter an issue while sending keys to a text box.
Sometimes the string is inputted to the box in a mixed order, for example:
test@some,domain.com --> test@some,domain.moc
Did anyone saw this behavior?
My environment is:
Appium 1.3.7
Mac OS X 10.10.2
Thanks in advance!!

Hi Ronen,

I met this issue right now on Android 6.0.1, and it always blocks my test case for assertions failed…
Did you solve this now ? …

Hi,

I haven’t encountered it lately.
We solved it by adding a check after the send keys and resend them if there was an error.
We are now using the latest release of appium but the android version is 5.1.1.

With appium 1.5.x it never failed for me.

Anyway, if you want you may use the following adb command directly:

adb shell input text your%stext%sin%shere

Note: The %s in previous command send space to textfield

Hi Ronen,

Thanks for your reply, I used Android 5.0 and installed a google input method , still got same issue…I also tried adb shell input, some times, still got wrong order…
, btw, how do you check if the send key is correct, use findelement, then gettext something like that?..

Hi Cardoso,

Thanks, I tried this before, still got wrong order of input character…just wondering if there’s some settings to control the speed of input…

Hi @fionazj,

for ios we have a capability to delay input of keys:

String INTER_KEY_DELAY = "interKeyDelay";

But there is no capability similar for android.

I guess you can try to do a method. I tried with delay above 250ms and it works properly. If I give less delay, some keys will be written before others :slight_smile:

public void mySendText(String text, int delay) throws IOException, InterruptedException {
    String ADB_SEND_TEXT = "adb shell input text %s";

    for (char ch: text.toCharArray()) {
        Runtime.getRuntime().exec((String.format(ADB_SEND_TEXT,ch)));
        Thread.sleep(delay);
    }
}
1 Like

Hi Cardoso,

Thanks for your suggestion, I do think it’s a good way to slow down the speed of sendkey. I will try it in the code later :slight_smile:

Hi fionazj,
Does this method , which is mentioned by Cardoso, works for you on Android platform? As I am also facing the same issue with Android version 6.

Hi
It works for me now you could have a try for this:grin:

Hi All,

I also facing same issue for sendkeys for Android OS version 7.0 and above.
Sendkeys() method is stop support for OTP text field.
I have used following solution:

otpElement.click();
((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.KEYCODE_1);
((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.KEYCODE_3);
((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.KEYCODE_4);
((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.KEYCODE_5);
((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.KEYCODE_8);
((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.KEYCODE_6);

Thanks