2012-09-12 33 views
0

如何在使用UI自動化測試時取消鍵盤? 我一直在尋找UIAElementUIATextField文檔,但找不到這樣的建議。UIAutomation [UITextField resignFirstResponder]

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

javascript代碼在iOS? – Mil0R3

+0

是的。我開始寫自動化測試,他們都在JavaScript :) – nacho4d

+0

在Java腳本上下文,試試這個=> http://stackoverflow.com/questions/5937339/ipad-safari-make-keyboard-disappear – Peres

回答

1

從UIAutomation,你真的沒有訪問內部做的事情一樣辭職第一響應 - UIAutomation就像你的應用程序的普通用戶。你能做:

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

2

這是一個老問題,但我現在必須處理這個問題。 這個命令工作完美:

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

這可行,但不適用於UITextViews – Jasper

相關問題