Android sendKeys() performance

I use appium for android automation and i have some performance issue with sendKeys() method.
For example, input of text performs 3-5 sec. I have tried to type text in filed in another way - using sendKeyEvent() method for all symbols in input text, but this approach is slow also.
Can anybody suggest some relatively quick way to type text with Appium in Android?
Thank you in advance.

I have found alternative approach for text input.
You can use adb shell for this purpose.
For example,
adb shell input text abcdefg, where “abcdefg” is input text.

Hi Can you please let me know how in java code we can call ‘adb shell input text abcdefg’ command? I am also facing lots os problem because of element.sendKeys() being slow.

Before executing of command you should perform focus on input field (click on it, for example).
Then, you could execute next java code:

String [] args = {"cmd", "start", "adb", "-s", your_device_uid, "shell", "input", "text", your_text};
Runtime runtime = Runtime.getRuntime();

Thanks for the reply.

I tried below code because I am using android emulator. Using “0000000000000” as device uid.

WebElement element=driver.findElement(“com.calculator:id/EditText01”));;
String [] args = {“cmd”, “start”, “adb”, “-s”, “0000000000000”, “shell”, “input”, “text”, “2”};
Runtime runtime = Runtime.getRuntime();

getting below exception - Cannot run program “cmd”: error=2, No such file or directory
at java.lang.ProcessBuilder.start(
at java.lang.Runtime.exec(
at java.lang.Runtime.exec(
at com.saucelabs.appium.AndroidTest.apiDemo(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
at org.junit.runners.model.FrameworkMethod.invokeExplosively(
at org.junit.internal.runners.statements.InvokeMethod.evaluate(
at org.junit.internal.runners.statements.RunBefores.evaluate(
at org.junit.internal.runners.statements.RunAfters.evaluate(
at org.junit.runners.ParentRunner.runLeaf(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.ParentRunner$
at org.junit.runners.ParentRunner$1.schedule(
at org.junit.runners.ParentRunner.runChildren(
at org.junit.runners.ParentRunner.access$000(
at org.junit.runners.ParentRunner$2.evaluate(
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(
at com.intellij.rt.execution.junit.JUnitStarter.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at com.intellij.rt.execution.application.AppMain.main(
Caused by: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.(
at java.lang.ProcessImpl.start(
at java.lang.ProcessBuilder.start(

Do you have any idea, why I am getting this exception? or what I am doing wrong?

I have got it working. Thanks. Using emulator id i.e. emulator-5554 instead of “000000000000000” solves my problem.

So for anyone else facing the same issue -

below is what you need to do in order to get your code working.

WebElement element=driver.findElement(“com.calculator:id/EditText01”));;
Process p = Runtime.getRuntime().exec("/Users/manjyotsingh/Library/Android/sdk/platform-tools//adb -s emulator-5554 shell input text 267");

1 Like

The only issue that I am facing now is, I have to give full path of adb instead of just “abd”(as mentioned above in the command). I have set path till platform-tools in PATH variable. If I write the command in terminal like “adb -s emulator-5554 shell input text 267”, it executes the command gracefully but when I am executing it from java code I have to give full path to adb.

Any solution to that?

Hi, the above solution works for me however there are times when only part of the text is being inputted. For example:

Runtime runtime = Runtime.getRuntime();
runtime.exec("cmd start adb -s 0000000000000 shell input text “1234567891111113”);

RESULT (text shown in phone): 12345

Runtime runtime = Runtime.getRuntime();
runtime.exec("cmd start adb -s 0000000000000 shell input text “30”);

RESULT (text shown in phone): 3

This happens randomly and there are times it works. I can’t pinpoint when it will happen and why.
Can somebody please help? Any ideas?


I have the exact same issue. I believe it to be a problem with the send key’s speed going too fast. You can manually replicate it in numeric input fields by pressing 123 really fast. Often times you get result of 12 and missing the second keystroke. Can we have abilitiy to set speed at which keys are sent to input field? Works great as is for text, but the problem seems to be isolated to numwric fields.

Actually, i found out its not a problem with appium or adb. Its a problem with the app. Some devs are typecasting for decimal coversion from string and the lib used for it is the problem.