【问题标题】:Swift UITest - No match found for textField with accessibility identifierSwift UITest - 找不到具有可访问性标识符的文本字段的匹配项
【发布时间】:2017-09-20 09:22:36
【问题描述】:

尝试创建一个 UITest,用于在文本字段中输入电子邮件地址/密码,然后点击登录按钮。使用 Xcode。

我看到 UITest 导航到正确的页面,但它没有检测到文本字段。我确保两个文本字段都选中了“辅助功能”框,并为它们提供了标识符。

我收到此错误:

UI 测试失败 - 未找到文本字段的匹配项

func testExample() {
    let app = XCUIApplication()

    //Test login page
    app.buttons["loginButton"].tap()

    //Here it navigates to the desired page 
    let emailField = app.textFields["email"]
    emailField.tap()
    emailField.typeText("xxx.xx.edu")

    let passwordField = app.textFields["password"]
    passwordField.tap()
    passwordField.typeText("xxx")

    app.buttons["loginButton"].tap()

   // let loginAlert = app.alerts["alertVC"]

   // XCTAssertEqual(loginAlert.title, "Error")        
}

可访问性指标分别是“电子邮件”和“密码”。当我自己运行模拟器时,登录工作正常。

编辑:显然根本没有文本字段(计数 = 0),即使我看到它们并在页面上使用它们...

带有文本字段的故事板图像:

【问题讨论】:

  • 我也有同样的问题????你找到解决办法了吗?

标签: swift xcode textfield uitest


【解决方案1】:

如果UITextFiled 设置SecureTextEntry true,你应该使用:

let passwordField = app.secureTextFields["password"]

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,我通过取消选中 ViewControllers 的“视图”的“启用辅助功能”框来解决

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-12
      • 1970-01-01
      • 2012-10-24
      • 2012-08-12
      相关资源
      最近更新 更多