keys
Send a sequence of key strokes to the "active" element. You can make an input element active by just clicking
on it. To use special characters like "ArrowLeft", "Enter", or "Backspace", import the Key object from the WebdriverIO package:
import { Key } from 'webdriverio'
The Key object provides constants for all special keys including:
- Navigation:
Key.ArrowLeft,Key.ArrowUp,Key.ArrowRight,Key.ArrowDown,Key.PageUp,Key.PageDown,Key.Home,Key.End - Editing:
Key.Enter,Key.Tab,Key.Backspace,Key.Delete,Key.Insert - Modifiers:
Key.Ctrl(cross-platform),Key.Shift,Key.Alt,Key.Control,Key.Command - Function keys:
Key.F1throughKey.F12 - Numpad:
Key.Numpad0throughKey.Numpad9,Key.Multiply,Key.Add,Key.Subtract,Key.Divide - And more:
Key.Escape,Key.Space,Key.Clear,Key.Pause, etc.
See the Key API docs for a complete list.
Modifier keys like Control, Shift, Alt and Command will stay pressed throughout the sequence and will be released
at the end. Modifying a click requires you to use the WebDriver Actions API through the
performActions method.
The Key.Ctrl constant provides a convenient way to use the "control" modifier across different operating systems.
On macOS, it maps to the Command key, while on Windows and Linux it maps to the Control key.
This is useful for keyboard shortcuts like select-all ([Key.Ctrl, 'a']), copy, or paste.
Usage
browser.keys(value)
Parameters
| Name | Type | Details |
|---|---|---|
value | String, String[] | The sequence of keys to type. An array or string must be provided. |
Example
loading...