【发布时间】:2017-09-04 11:40:58
【问题描述】:
我正在尝试从文本视图中删除以前的值,但由于光标始终位于文本视图的开头,所以我无法删除。我正在使用
extension XCUIElement {
/**
Removes any current text in the field before typing in the new value
- Parameter text: the text to enter into the field
*/
func clearAndEnterText(text: String) -> Void {
guard let stringValue = self.value as? String else {
XCTFail("Tried to clear and enter text into a non string value")
return
}
self.tap()
let deleteString = stringValue.characters.map { _ in XCUIKeyboardKeyDelete }.joinWithSeparator("")
self.typeText(deleteString)
self.typeText(text)
}
}
【问题讨论】:
-
您的文本字段上有清除按钮吗? (右侧的小灰色 x 按钮)
标签: ios xctest ui-testing