<!--
{
  "availability" : [
    "Xcode: 16.3.0 -",
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "XCUIAutomation",
  "identifier" : "/documentation/XCUIAutomation/XCUIElementTypeQueryProvider/firstMatch",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "XCUIAutomation"
    ],
    "preciseIdentifier" : "c:objc(pl)XCUIElementTypeQueryProvider(py)firstMatch"
  },
  "title" : "firstMatch"
}
-->

# firstMatch

The first element that matches the query.

```
var firstMatch: XCUIElement { get }
```

## Discussion

Use the [`firstMatch`](/documentation/XCUIAutomation/XCUIElementTypeQueryProvider/firstMatch) property when you know that there can only be one possible match for an element query. When you call [`firstMatch`](/documentation/XCUIAutomation/XCUIElementTypeQueryProvider/firstMatch), the framework stops traversing your app’s accessibility hierarchy as soon as it finds a matching element, speeding up element query resolution.

> Note:
> Only use ``doc://com.apple.xcuiautomation/documentation/XCUIAutomation/XCUIElementTypeQueryProvider/firstMatch`` in cases where you know categorically that a single element matches a query. Accessing the ``doc://com.apple.xcuiautomation/documentation/XCUIAutomation/XCUIElementTypeQueryProvider/firstMatch`` property doesn’t check for multiple conflicting matches in ambiguous cases. Use ``doc://com.apple.xcuiautomation/documentation/XCUIAutomation/XCUIElementQuery``‘s ``doc://com.apple.xcuiautomation/documentation/XCUIAutomation/XCUIElementQuery/element`` property instead if you want to check for multiple matches before using the element, and to fail the test if there isn’t a single unique match.

## See Also

[`element`](/documentation/XCUIAutomation/XCUIElementQuery/element)

The query’s single matching element.



---

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)