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

# descendants(matching:)

Returns a query for all descendants of the element matching the type you specify.

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

## Discussion

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

---

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)