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

# containing(_:)

Returns a new query that matches elements containing a descendant that meets the logical conditions of the provided predicate.

```
func containing(_ predicate: NSPredicate) -> XCUIElementQuery
```

## Parameters

`predicate`

The predicate used to evaluate each descendant element.

## Return Value

A new query that defines a search that extends the search criteria of the receiver. The new search finds elements that match the original search and contain elements that meet the logical conditions of the provided predicate.

## Discussion

The predicate evaluates against objects that conform to the [`XCUIElementAttributes`](/documentation/XCUIAutomation/XCUIElementAttributes) protocol.

> Note:
> Where possible, use <doc://com.apple.documentation/documentation/Foundation/NSExpression>-based or format-string-based predicates with this method in preference to block-based predicates. This enables the framework to optimize the query’s performance.

---

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)