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

# typeText(_:)

Types a string into the element.

```
func typeText(_ text: String)
```

## Discussion

The element or a descendant must have keyboard focus; otherwise the system raises an error. This API discards any modifiers set in the current context by [`perform(withKeyModifiers:block:)`](/documentation/XCUIAutomation/XCUIElement/perform(withKeyModifiers:block:)) so that it strictly interprets the provided text. To input keys with modifier flags, use  [`typeKey(_:modifierFlags:)`](/documentation/XCUIAutomation/XCUIElement/typeKey(_:modifierFlags:)-6gaoi).

---

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)