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

# containing(_:)

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

## Declaration

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

## Parameters

- `predicate`: The predicate used to evaluate each descendant element.

## Return Value

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

Discussion The predicate evaluates against objects that conform to the XCUIElementAttributes protocol. note: Where possible, use 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.

## See Also

### Creating new queries

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