我知道我可以查询文本字段、表、按钮,但不能查询标签,为什么?
app.textFields["Username"].typeText("bcyops")
app.secureTextFields["Password"].typeText("ops15")
app.buttons["Submit"].tap()
app.tabBars.buttons["Main"].tap()
let tablesQuery = app.tables
如果你的意思是标签是静态文本元素,你可以查询标签:
let label = app.staticTexts["yourLabelIdentifier"]
如果您需要标签中的文本
let textInLabel = app.staticTexts["yourLabelIdentifier"].label
所有元素类型的文档都在这里:https://developer.apple.com/documentation/xctest/xcuielementtypequeryprovider
标签在XCTest UI测试中被称为staticTexts
。
app.staticTexts["myLabel"].exists
您可以使用NSPredcates查询具有指定标签的元素:
app.textViews.element(matching: NSPredicate(format: "label LIKE theLabelYoureLookingFor"))