nacho4d
nacho4d

Reputation: 45088

UIAutomation [UITextField resignFirstResponder]

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
}

Upvotes: 0

Views: 1225

Answers (2)

Henrique
Henrique

Reputation: 21

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

target.frontMostApp().keyboard().typeString("\n");

Upvotes: 2

MaxGabriel
MaxGabriel

Reputation: 7707

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(); ?

Upvotes: 1

Related Questions