在 Swift 中使用 UITextfield 类,您可以执行如下功能:
private func signIn() {
if emailTextField.text?.characters.count == 0 {
invalidEmailLabel.text = NSLocalizedString("Required", comment: "Required text field")
Constants.FormValidation.showValidationLabel(invalidEmailLabel)
return
}
有什么方法可以用 XCUIElements 做同样或类似的事情吗?
我想做这样的事情:
func testExample() {
let app = XCUIApplication()
let emailTextField = app.textFields["username"]
if emailTextField.text.characters.count == "0"{
let emailTextField = app.textFields["username"]
emailTextField.tap()
emailTextField.typeText("example")
let passwordTextField = app.secureTextFields["password"]
passwordTextField.tap()
passwordTextField.typeText("whatever")
app.buttons["Done"].tap()
}
if emailTextField.text.characters.count != "0"{
let passwordTextField = app.secureTextFields["password"]
passwordTextField.tap()
passwordTextField.typeText("whatever")
app.buttons["Done"].tap()
}
怎样才能让它发挥作用?
谢谢。
最佳答案
您可以通过执行以下操作来计算文本字段元素的字符数:
let emailValue = emailTextField.value as! String
if emailValue.characters.count == 0 {
// do something
}
关于ios - 有没有办法计算 XCUIElement 文本字段的字符数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37890890/