How to send keys slowly (if supported at all) in Java Client (Android)

I have a couple WebView actions in the native app I’m tested that don’t behave very well with sendKeys or setValue. However, if I slow down the input with a loop and only enter 1-2 characters at a time it “works”. The workaround in Android to do this is to loop through and call “setValue”. sendKeys clears the field, keyboardSendKeys looks like the WebDriver selects the element, with a long press or something therefore selecting the text already sent.

So I’m looking for a one-stop (or even a “script” or something) in the Java client to say send “abcdefghi” one key at a time without clicking in the element every time (which setValue does, slowing the already slow input down), or to have a “delay” option with sendKeys to slow it down in some instances.

Java Client 5.0.0-BETA9
Appium Server 1.6.6-beta.4

// Tried these, but they all do the same thing of
// POST /wd/hub/session/30bd4df9-9fa1-40f3-973e-65b76ad9cda6/keys {"value":["ti"]}
// appiumDriver.getKeyboard().sendKeys(characters);
// element.execute(DriverCommand.SEND_KEYS_TO_ACTIVE_ELEMENT, ImmutableMap.of("value", characters));

// This doesn't work, it tries:
// POST /wd/hub/session/4c18f1d5-916f-4b11-a2a1-605587559dfa/element/9/value {"id":"9","value":["il"]}
// element.sendKeys(characters);

// This one works for some reason, but does click (or tap) in the middle of the element first (so a long string won't work)
// POST /wd/hub/session/53307101-405d-4f80-828b-7c6d57a52b90/appium/element/9/value {"id":"9","value":"to"}



  1. did you try replaceValue?
  2. did you try switch driver into WebView before send text?

I’m not familiar with replaceValue, and haven’t tried to switch the driver into the WebView. All the other fields seem to fill correctly (to be fair this is a CC# field, so there’s possibly some JS going on so sending keys are really sending them, but they’re being gobbled up).

I also just noticed I’m not using uiautomator2 currently… however, in switching it, I’ve found a BUNCH of other places that aren’t working correctly now :frowning:


you should switch to uiautomator2 when Android 7+. try replaceValue and all setValue,replaceValue,sendKeys after switching to webView. Note that after switching into webView you should find your elements same as with WebView way. To see how it is look like execute:

// java

after switching into webview.

@bennid another way to try do click on this element and type with keyboard:

((AndroidDriver) driver).getKeyboard().pressKey(...);
((AndroidDriver) driver).getKeyboard().sendKeys(...);

the sendKeys() definitely is partially selecting what’s already been entered… but I"ll see about pressKey() Lots to try, thanks!