4

I'm trying to automate keyboard typing with UI Automation.

target.frontMostApp().keyboard().typeString("INTERCOM")

But i will get this error after first 'I' is typed

target.frontMostApp().keyboard() failed to locate key 'N'
Script threw an uncaught JavaScript error: target.frontMostApp().keyboard() failed to locate key 'N'

I have a localized swedish keyboard.

Anyone know if this a bug or something I've missed?

bollhav
  • 543
  • 6
  • 11
  • You might probably just have the keyboard layout set to an "exotic" language with a non latin alphabet. I encounter the same issue as you do with the space bar though. Which is even more odd – Bgi Dec 21 '12 at 11:39

3 Answers3

2

This might help:

var vKeyboard = target.frontMostApp().keyboard();
vKeyboard.setInterKeyDelay(0.1);
vKeyboard.typeString("INTERCOM");

By default this delay is set with 0.03 seconds. This is not enough for your application to update the keys on your keyboard. Increasing this timeout between determining keys for typeString keyboard method will help you. There is no description for setInterKeyDelay on UIAKeyboard reference page but this method is available for UIAKeyboard. Also I'm not sure about other languages. I do not know if typeString allows to type on other languages but this 100% works for English keyboard for iOS 5.x.

Sh_Andrew
  • 352
  • 2
  • 6
1
try{
    target.delay(1);
    target.frontMostApp().mainWindow().textFields()[0].tap();
    target.delay(1);
    target.frontMostApp().mainWindow().textFields()[0].setValue("INTERCOM");
}
catch(err){
    target.delay(1);
    target.frontMostApp().mainWindow().scrollViews()[0].textFields()[0].tap();
    target.delay(1);
    target.frontMostApp().mainWindow().scrollViews()[0].textFields()[0].setValue("INTERCOM");
}
Ron D.
  • 3,774
  • 6
  • 31
  • 39
  • Unfortunately, this solution doesn't cause the delegate methods for the text entry/editingDidChange to get called. That's typically why people reach for a "typing" solution. – Prometheus Jun 15 '12 at 19:04
-1

I've had this problem as well and I believe it's a case of the string being typed too quickly.

It seems that the names of the key,change depending on the status of the shift button.If shift is enabled then the key is called 'N',if shift is not enabled then it's 'n'.You'll notice as a string is being typed,that the shift button is tapped before an uppercase letter is typed.Your test is attempting to press the 'N' key before the 'Shift' button has been pressed.It doesn't affect the first letter of your sentence because the keyboard has shift enabled for the first letter.

This also affects typing a lowercase character after an uppercase character:the lowercase character may be typed whilst the shift button is in the process of being unpressed.

I use a workaround of typing each letter of the string with separate typeString() methods.

for (i = 0; i < title.length; i++)
{
    var strChar = title.charAt(i);
    target.frontMostApp().keyboard().typeString(strChar);
}

The downside to this is that it takes a lot longer to type the full string.

You may also want to look at the following link which provides a similar solution but uses the app.keyboard().keys().tap() method for each character of the string instead of the typeString() method. http://jojitsoriano.wordpress.com/2011/06/27/ios-ui-automation-typing-a-string-in-a-uiatextfield/