Issues with sending keys to or replacing value of text field on Android
See original GitHub issueDescription
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 usingPhone
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, erasesPhone
up toP
and then typesPhonPhone
, resulting inPPhonPhone
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.
- What I see is Appium dragging out my left sidebar just a little bit (let’s say ~30-50 pixels) and then typing
- 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.
- 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
-
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.
- I’m not sure how to access this function in java_client, but it routed to
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:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The
setValue
is going to be available on Android from the new release.I’m closing this issue in favor of Android’s
setValue
and Appium’s adbclear
logic.Haven’t had any issues with text input after these two updates.