0

使用 UI 自动化测试时如何关闭键盘?我一直在查看UIAElementUIATextField文档,但找不到建议的内容。

var textField = toolbar.textFields()[0];
var textView = toolbar.textViews()[0];
function testFeature1() {
    if (textField.hasKeyboardFocus() || textView.hasKeyboardFocus()) {
        // Resign first responder .. How?
    }
    // Do my tests
}
4

2 回答 2

2

这是一个很老的问题,但我现在必须处理这个问题。该命令完美运行:

target.frontMostApp().keyboard().typeString("\n");
于 2015-05-07T22:09:42.307 回答
1

从 UIAutomation 中,您实际上无法访问内部来执行诸如辞职第一响应者之类的事情——UIAutomation 就像您的应用程序的普通用户一样。你能做到吗:

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

于 2012-10-07T00:17:29.027 回答