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

# element(matching:)

Matches the predicate.

## Declaration

```swift
func element(matching predicate: NSPredicate) -> XCUIElement
```

## Parameters

- `predicate`: The predicate to match.

## 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

### Accessing matched elements

- [allElementsBoundByAccessibilityElement](xcuiautomation/xcuielementquery/allelementsboundbyaccessibilityelement.md)
- [allElementsBoundByIndex](xcuiautomation/xcuielementquery/allelementsboundbyindex.md)
- [count](xcuiautomation/xcuielementquery/count.md)
- [element](xcuiautomation/xcuielementquery/element.md)
- [element(boundBy:)](xcuiautomation/xcuielementquery/element(boundby:).md)
- [element(matching:identifier:)](xcuiautomation/xcuielementquery/element(matching:identifier:).md)
- [subscript(_:)](xcuiautomation/xcuielementquery/subscript(_:).md)
- [element(at:)](xcuiautomation/xcuielementquery/element(at:).md)
