首页 > 解决方案 > How to query labels in Xcode UI testing

问题描述

I see I can query textfields, tables, buttons, but not labels, why?

app.textFields["Username"].typeText("bcyops")
app.secureTextFields["Password"].typeText("ops15")
app.buttons["Submit"].tap()
app.tabBars.buttons["Main"].tap()
let tablesQuery = app.tables

标签: xcode-ui-testing

解决方案


如果您的意思是将标签作为静态文本元素,您可以查询标签:

let label = app.staticTexts["yourLabelIdentifier"]

如果您需要标签中的文字

let textInLabel = app.staticTexts["yourLabelIdentifier"].label

所有元素类型的文档都在这里:https ://developer.apple.com/documentation/xctest/xcuielementtypequeryprovider


推荐阅读