XCUIElement Queries
Find elements using element types and identifier attributes.
Common element queries
swift
let app = XCUIApplication()
// By element type
app.buttons["Login"].tap()
app.textFields["email"].tap()
app.secureTextFields["password"].typeText("secret")
app.staticTexts["Welcome"].exists
app.images["profile-avatar"].exists
app.switches["notifications"].tap()
app.tables.cells.element(boundBy: 0).tap()
app.collectionViews.cells["ProductCell"].tap()
// By accessibility identifier (preferred)
app.buttons.matching(identifier: "submit-btn").firstMatch.tap()
// Find within a container
let form = app.otherElements["login-form"]
form.textFields["email"].typeText("alice@example.com")
// Nth element
app.tables.cells.element(boundBy: 2).tap()
app.buttons.element(boundBy: 0).tap()
// All elements of a type
let allCells = app.tables.cells
print("Cell count: \(allCells.count)")