question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with sending keys to or replacing value of text field on Android

See original GitHub issue

Description

I have a search box in my app that I’m trying to automate by sending text to it twice. My app also has a collapsed sidebar which can be pulled out by swiping right from the left edge of the screen (picture the google now app). I’m unable to share code or screenshots due to company policy. Here are the problems that I’ve run into:

  • I tried clicking on the search box and using driver.getKeyboard().sendKeys("Phone"); twice. (I’ll be using Phone as an example test string here)
    • What I see is Appium dragging out my left sidebar just a little bit (let’s say ~30-50 pixels) and then typing Phone in the seach box. The second time is the most bizarre where Appium still drags out the sidebar a little bit, erases Phone up to P and then types PhonPhone, resulting in PPhonPhone in my search box. There’s nothing in the Appium logs which hints to where this strange text is resulting from. Apparently it’s trying to imitate appending text, but it’s deleting one less character and also restoring one less character from the previous text.

  • Next I tried locating the search box and calling element.replaceValue("Phone"); on the already filled search box. This is not ideal anyways since I’m interested in appending to my query the second time.
    • What I notice is Appium slowly hitting backspace one letter at a time, pausing, again dragging out my left sidebar a bit, then instantly removing the remainder of the text, and typing Phone. This function at least correctly removes the previous text and replaces it with what I wanted, but it’s very slow and unable to append to my previous input.

  • Finally I came up with the code below after reading through Appium and java_client’s source code.

    ImmutableMap.Builder args = ImmutableMap.builder().put("id", element.getId()).put("value", "Phone");
    driver.execute("setValue", args.build());
    
    • I’m not sure how to access this function in java_client, but it routed to setValueImmediate on Appium which in turn routed to adb. This was exactly what I was looking for since it inputted text without weird pauses or pulling out my sidebar. It also allowed me to append to an already populated text box. But it seems a bit hacky to me.

Environment

  • java client build version or git revision if you use some shapshot: 4.0
  • Appium server version or git revision if you use some shapshot: 1.5.2
  • Mobile platform/version under test: Android 6.0
  • Real device or emulator/simulator: Nexus 6P

Link to Appium logs

Logs for sendKeys since it appears to be the only usecase that’s completely buggy for me: https://gist.github.com/ssynix/302595c5accadbaf55fede8fbbd978f3

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
TikhomirovSergeycommented, Jul 16, 2016

The setValue is going to be available on Android from the new release.

0reactions
ssynixcommented, Sep 29, 2016

I’m closing this issue in favor of Android’s setValue and Appium’s adb clear logic.

Haven’t had any issues with text input after these two updates.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to sendKeys in an EditText field - java - Stack Overflow
Unable to sendKeys in an EditText field ... I am having issues on performing send keys in a particular EditText field. I tried...
Read more >
'sendKeys' appends the word 'Search' with my text - Support
The text field is empty initially and I am sending the text 'auto' only. I have even tried el.clear() before sending keys, issue...
Read more >
Specify the input method type - Android Developers
Every text field expects a certain type of text input, such as an email address, phone number, or just plain text.
Read more >
<input type="text"> - HTML: HyperText Markup Language | MDN
<input type="text"> · Try it · Value · Additional attributes · Non-standard attributes · Using text inputs · Validation · Examples · Technical...
Read more >
Selenium Form WebElement: TextBox, Button, sendkeys ...
Input boxes refer to either of these two types: ... Password Fields– text boxes that accept typed values but mask them as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found