I've been having more problems with send_keys on Android

send_keys has not worked for me in the past. Clearing out the previous value is the biggest problem but it has gotten worse. Removing spaces from my test data helped this a little but email addresses with the @ continued to be a problem. I just upgraded to 1.3.1 and it may have gotten worse but looks like it is trying harder. The ‘Pointer location’ option on in the developer options so I see lots of clicks and attempts to select all but it is failing too often to get green tests results now. I’m using a nexus 4 on OS X 10.9.5 and rebooting the phone and restarting Appium often but no luck.

I’m going to write some defensive code to set text values but wanted to check here as this will slow down my already long test runs. I’ll post the code here when I’m done if anyone is interested.

This is what I went with. The attribute parameter is the method that returns the Selenium element and value is what to set it to. The check to see if the value is already set to what you are about to set it to makes some tests much faster when the app remembers reused values. It may not be what you want but it works for me. We then try 8 times to set it right, if we don’t manage to we just finish and let the test figure out that something is wrong.

One more improvement was to turn on the unicode keyboard. A problem I still have not fully figured out is, on occasion, I will send_keys to element 1, then when I go to send_keys to element 2 it will delete some of element 1. This is a sometimes problem.

def set_text_element attribute, value
  compare_value = value.chomp
  element = send attribute
  8.times do |try|
    current_value = element.text
    return if current_value == compare_value
    puts "Tried to set #{attribute} to #{compare_value.inspect} it was #{current_value.inspect} instead" if try > 0
    element.clear if ((try % 2)== 1) || current_value.include?(value)
    if try % 3 == 2
      sleep 0.1
      element.clear unless element.text.size == 0
      sleep 0.1
    element.send_keys value