【发布时间】:2019-12-13 09:15:53
【问题描述】:
我不确定为什么,但无论我尝试什么,即使我检查它并看到与要删除的字符相同数量的删除字符,这似乎也不会删除文本字段中的整个文本。它似乎是随机的,每次迭代删除不同数量的字符。
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) {
guard let stringValue = self.value as? String else {
XCTFail("Tried to clear and enter text into a non string value")
return
}
let deleteString = String(repeating: XCUIKeyboardKey.delete.rawValue, count: stringValue.count)
self.typeText(deleteString)
self.typeText(text)
}
}
【问题讨论】:
-
您可以轻松做到。
self.typeText.text = "" -
@Putte 谢谢。但是,它不起作用。它将“”附加到文本字段中的现有字符串。
-
那么,您为什么要使用 XCUIElement?你从中得到什么?我刚刚意识到 typeText() 是一个内置属性,对吧?
-
我从链接stackoverflow.com/questions/32821880/…得到这个代码
-
有时会按预期删除所有字符,但有时会留下 2 或 3 个字符未删除。
标签: swift