---
title: "descendants(matching:)"
framework: xcuiautomation
role: symbol
role_heading: Instance Method
path: "xcuiautomation/xcuielementquery/descendants(matching:)"
---

# descendants(matching:)

Returns a new query that matches all descendants of the requested type.

## Declaration

```swift
func descendants(matching type: XCUIElement.ElementType) -> XCUIElementQuery
```

## Parameters

- `type`: The element type to match.

## Return Value

Return Value A new query that defines a search that extends the search criteria of the receiver. The new search finds all decendant of elements that match the original search and are of the requested type. For a list of the types, see XCUIElement.ElementType.

## Discussion

Discussion Because XCUIElementQuery conforms to the XCUIElementTypeQueryProvider protocol, you can use the protocol’s properties as shorthand for calling descendants(matching:) for different element types. For example, rather than calling query.descendants(matching: .button), you can use the buttons property from the protocol to retrieve query.buttons.

## See Also

### Creating new queries

- [children(matching:)](xcuiautomation/xcuielementquery/children(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)
