Instance Method

typeKey(_:modifierFlags:)

Types a single key with the specified modifier flags.

Declaration

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

Parameters

key

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.

flags

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

Discussion

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.