Instance Method


Types a single key with the specified modifier flags.


func typeKey(_ key: String, modifierFlags flags: XCUIElement.KeyModifierFlags)



A string representation of the key to type, or a constant from XCUIKeyboardKey for a key that does not have a single-key string equivalent.


A set of modifier flags (XCUIElement.KeyModifierFlags) to use when typing the key.


Although key is a string, it must represent a single key on a physical keyboard. Strings that resolve to multiple keys will raise an error at runtime.

In addition to literal string key representations like "a", "6", and "[", keys such as arrow keys, command, control, option, and function keys can be typed using the constants in XCUIKeyboardKey.

See Also

Using Key Modifiers

struct XCUIKeyboardKey

Constants for use with typeKey(_:modifierFlags:) to represent keys that have no textual equivalent.

struct XCUIElement.KeyModifierFlags

Flags for keyboard modifiers such as shift, control, option, and command.