Search code examples
iphoneiosinstrumentsui-automationios-ui-automation

Clicking keyboard 'Next' key using UIAutomation


I have a search field in my app and I have set the return key type of the keyboard for this field to UIReturnKeyNext. I am attempting to write a UIAutomation test that clicks the Next button on the keyboard using the following line:

UIATarget.localTarget().frontMostApp().mainWindow().keyboard().keys().firstWithName("next");

This call is failing because the key with name 'next' is not being found. I have done a dump of all of the elements in my app using:

UIATarget.localTarget().frontMostApp().logElementTree();

This reveals that there is indeed a key in the keyboard with name 'next', but somehow my attempt to retrieve it as show above still fails. I can however retrieve other keys (like the key for the letter 'u') using this method. Is there a known issue here or am I doing something wrong?

I've tried other variations with no luck:

UIATarget.localTarget().frontMostApp().mainWindow().keyboard().elements()["next"];

Here is a screen capture of the elements in my UIAKeyboard:

return key dump


Solution

  • The following works for me:

    UIATarget.localTarget().frontMostApp().mainWindow().keyboard().buttons().firstWi‌​thPredicate("name contains[c] 'next'");