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:
driver.getKeyboard().sendKeys("Phone"); twice. (I'll be using Phone as an example test string here)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.
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());
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.java client build version or git revision if you use some shapshot: 4.0
1.5.2Android 6.0Nexus 6PLogs for sendKeys since it appears to be the only usecase that's completely buggy for me:
https://gist.github.com/ssynix/302595c5accadbaf55fede8fbbd978f3
@imurchie your thoughts on this please
I think it makes sense to try the _setValue_ method on Android. It was not being possible with Appium server 1.4.x
@ssynix Also I think you are facing some server-side problem.
From what I can see, setValue was moved to IOSElement from MobileElement at some point, which is why I haven't been able to access it in my test on Android.
Any idea why sendKeys would affect the app's sidebar? Is appium/uiautomator trying to swipe on the textbox for some reason and doesn't get the bounds right?
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 adb clear logic.
Haven't had any issues with text input after these two updates.
Most helpful comment
The
setValueis going to be available on Android from the new release.