Java-client: Issues with sending keys to or replacing value of text field on Android

Created on 28 Jun 2016  路  5Comments  路  Source: appium/java-client

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

Needs investigation server side

Most helpful comment

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

All 5 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings