Suggestion/Request for improving sendKeys()

Hi Appium Dev team,
I have a suggestion about improving the performance or reducing the time of input using the sendKeys() function. There are lots of issues post are coming in this forum for sendKeys() function.

From what i understand the behavior of sendKeys() function is, It takes the parameter passed in it and sends the text over the adb shell (I’m not sure if that way it’s happening?)

adb shell input text "parameter"

My idea is that rather then sending the data to the input field directly

  1. Copy the data in clipboard of the device.
  2. Now paste the data from clipboard.

If it’s possible to achieve this, the length of the string would be irrelevant (i hope).
While I’m working on doing this using Java, I request everyone to give your thoughts on this idea.
@jonahss @Hassan_Radi @bootstraponline @jlipps @SergeyTichomirov please look into this if it’s feasible.

2 Likes

As far as I can tell, most of the time taken while sending keys is wasted in clearing any pre-filled text or any hint text. The sendkeys function sure needs some improvements to be as stable as its Selendroid’s counterpart.

Your suggestion sounds logic and I think it might work. We just need to try it out and see if it can handle all of the special cases that are causing a lot of bugs right now…

2 Likes

Interesting idea. SendKeys should simulate typing individual keys on the keyboard, but maybe we could use this approach for setValue. What does @bootstraponline think?

Is send_keys working for you guys on iOS using Xcode6?
It only works for me if I have test in the textfields by default.
But, if I clear it out first, it does not work.

I have pressed cmd+k and tried to implement the soft keyboard several times.
I imagine that I am doing something wrong on my side, but I can not figure out what.

Any help would be VERY appreciated.

Thank You!

The problem with send keys on Android is we can’t reliably clear the textfield using uiautomator. The proper fix for this is rearchitecting android support to use an instrumentation(via Espresso)/uiautomation hybrid so we can call instrumentation methods that are much less flaky than uiautomator.

adb shell input text or messing with the clipboard are ways to input text. It doesn’t solve the problem of clearing the textfields which is what sendKeys must do according to the spec.

I Use a workaround that solves the clear text problem and it’s working pretty fine for me.

The steps are:

  • Long tap in the center of the textfield to select all of the text.
  • Send the delete key to clear the selected text.

Maybe we can add that clearing method to the list of the methods that are called to clear text.

The problem is not all textfields will highlight the text when tapped.

Is there any alternative, faster way than sendKeys, to populate text field in android? I tried clicking element and performing sendKeyEvent multiple times, to send every key separately, and it is faster with small amount of characters, it doesn’t clear textbox, but I don’t need that. Do you know some better way? It would be useful to add flag for sendKeys method to clear/don’t clear text before input.

1 Like

Hi @smartinovic , have you managed to solve the sendkey issue ?

thanks

I now use directly adb command for input text, ie have method that clicks on desired text field and calls adb input text command, I have flag for clearing text field, if true I call clear method, which is not perfect because if you have textbox that moves on click clear() method will fail, so I need to click on textbox even before clear method.

 public void sendKeys(String keysToSend, boolean clear) {
    if (clear && text != null && keysToSend.equals(text))
        return;
    if (clear) {
        click();
        getElement().clear();
    }
    click();
    AdbUtil.inputText(keysToSend);
    text = keysToSend;
}

I have problem that I try to type all text as example :

I want to fill text-box with automate user

But it actually types autsr !!!

It seems that appium is too fast to type all character.

Any solution ??!!

1 Like

for me it works better replace instead sendkey.

Some_AndroidElement.replaceValue("some_text");

Is replaceValue implemented in all language bindings?

I am also unable to use sendkeys while selecting and using DatePicker in Andoid using Appium.