简体   繁体   中英

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
}

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM