---
title: XCUIElementQuery
framework: xcuiautomation
role: symbol
role_heading: Class
path: xcuiautomation/xcuielementquery
---

# XCUIElementQuery

An object that defines the search criteria a test uses to identify UI elements.

## Declaration

```swift
@MainActor class XCUIElementQuery
```

## Mentioned in

Recording UI automation for testing

## Discussion

Discussion Use element queries to find UI elements in your app that you interact with in the tests, to test for the presence of expected elements, or to discover elements to test their values. For example, this test uses an element query to find the “Add Book” button, and after clicking the button, checks that there’s one button in an outline view cell titled “Untitled Book”. If the test can’t find the “Add Book” button, or there isn’t one “Untitled Book” cell, then the test fails. @MainActor func testClickingAddCreatesAnUntitledBook() throws {     let app = XCUIApplication()     app.launch()     let list = app.windows["Reading Journal"]     list.toolbars.children(matching: .button)["Add Book"].click()     XCTAssertEqual(list.outlines["Sidebar"].cells.containing(.button, identifier:"Untitled Book").count, 1) }

## Topics

### Creating new queries

- [children(matching:)](xcuiautomation/xcuielementquery/children(matching:).md)
- [descendants(matching:)](xcuiautomation/xcuielementquery/descendants(matching:).md)
- [containing(_:)](xcuiautomation/xcuielementquery/containing(_:).md)
- [containing(_:identifier:)](xcuiautomation/xcuielementquery/containing(_:identifier:).md)
- [matching(identifier:)](xcuiautomation/xcuielementquery/matching(identifier:).md)
- [matching(_:)](xcuiautomation/xcuielementquery/matching(_:).md)
- [matching(_:identifier:)](xcuiautomation/xcuielementquery/matching(_:identifier:).md)

### Accessing matched elements

- [allElementsBoundByAccessibilityElement](xcuiautomation/xcuielementquery/allelementsboundbyaccessibilityelement.md)
- [allElementsBoundByIndex](xcuiautomation/xcuielementquery/allelementsboundbyindex.md)
- [count](xcuiautomation/xcuielementquery/count.md)
- [element](xcuiautomation/xcuielementquery/element.md)
- [element(boundBy:)](xcuiautomation/xcuielementquery/element(boundby:).md)
- [element(matching:)](xcuiautomation/xcuielementquery/element(matching:).md)
- [element(matching:identifier:)](xcuiautomation/xcuielementquery/element(matching:identifier:).md)
- [subscript(_:)](xcuiautomation/xcuielementquery/subscript(_:).md)
- [element(at:)](xcuiautomation/xcuielementquery/element(at:).md)

### Debugging element queries

- [debugDescription](xcuiautomation/xcuielementquery/debugdescription.md)

### Identifying window buttons

- [XCUIIdentifierCloseWindow](xcuiautomation/xcuiidentifierclosewindow.md)
- [XCUIIdentifierFullScreenWindow](xcuiautomation/xcuiidentifierfullscreenwindow.md)
- [XCUIIdentifierMinimizeWindow](xcuiautomation/xcuiidentifierminimizewindow.md)
- [XCUIIdentifierZoomWindow](xcuiautomation/xcuiidentifierzoomwindow.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [XCUIElementTypeQueryProvider](xcuiautomation/xcuielementtypequeryprovider.md)

## See Also

### UI element queries

- [XCUIElementTypeQueryProvider](xcuiautomation/xcuielementtypequeryprovider.md)
