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

# element(matching:)

Matches the predicate.

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

## Parameters

`predicate`

The predicate to match.

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