0

How can I get the keyboard dismissed when using UI Automation tests? I've been looking at UIAElement and UIATextField documentation but couldn't find something that suggests so.

var textField = toolbar.textFields()[0];
var textView = toolbar.textViews()[0];
function testFeature1() {
    if (textField.hasKeyboardFocus() || textView.hasKeyboardFocus()) {
        // Resign first responder .. How?
    }
    // Do my tests
}
nacho4d
  • 43,720
  • 45
  • 157
  • 240

2 Answers2

2

Quite an old question but I had to deal with that right now. This command worked perfectly :

target.frontMostApp().keyboard().typeString("\n");
Henrique
  • 21
  • 1
  • 4
1

From UIAutomation, you don't really have access to the internals to do things like resign first responder--UIAutomation is just like a regular user of your app. Could you do:

app.keyboard().buttons()["return"].tap(); ?

MaxGabriel
  • 7,617
  • 4
  • 35
  • 82