Search code examples
iosseleniumautomated-testsappiumappium-ios

Appium iOS driver can't send keys to UIATextField


I am using Appium 1.4.13, java-client-3.3.0.jar, selenium standalone server 2.48.2 with IntelliJ.

I want to enter a value to UIATextField, which is a numberpicker. I read a tutorial and it suggested:

(MobileElement) iosDriver.findElement(By.xpath("//UIATextField")).sendKeys("abcdef");

but this didn't work: it just opened a native numberpicker from iOS

Another suggestion is to use setValue for java client 2.2.0:

(MobileElement) iosDriver.findElement(By.xpath("//UIATextField")).setValue("abcdef");

But setValue method is not there anymore.

So I have a workaround like below and it works:

(MobileElement) iosDriver.findElement(By.xpath("//UIATextField")).click;
iosDriver.scrollToExact("abcdef");
//click confirm

My questions:

  • setValue and sendKeyEvents are not available anymore?
  • is there a better way to enter a value and confirm it?

Thanks

This is what I got from Appium Inspector when I run

(MobileElement) iosDriver.findElement(By.xpath("//UIATextField")).sendKeys("170");

enter image description here


Solution

  • setValue changed to be only valid for IOSElement. Cast your element accordingly and it should work. Ex: (IOSElement) iosDriver.findElement(By.xpath("//UIATextField")).setValue("abcdef");

    Source: https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/ios/IOSElement.java