<!--
{
  "availability" : [
    "Xcode: 16.3.0 -",
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "XCUIAutomation",
  "identifier" : "/documentation/XCUIAutomation/XCUIElementQuery/descendants(matching:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XCUIAutomation"
    ],
    "preciseIdentifier" : "c:objc(cs)XCUIElementQuery(im)descendantsMatchingType:"
  },
  "title" : "descendants(matching:)"
}
-->

# descendants(matching:)

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

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

## Parameters

`type`

The element type to match.

## 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`](/documentation/XCUIAutomation/XCUIElement/ElementType).

## Discussion

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)