keys
Send a sequence of key strokes to the active element. You can also use characters like "Left arrow" or "Back space". WebdriverIO will take care of translating them into unicode characters. You’ll find all supported characters here. To do that, the value has to correspond to a key from the table.
Modifier like Ctrl, Shift, Alt and Meta will stay pressed so you need to trigger them again to release them. Modifiying a click however requires you to use the WebDriver Actions API through the performActions method.
Usage
browser.keys(value)
Parameters
Name | Type | Details |
---|---|---|
value | String , Array.<String> | The sequence of keys to type. An array or string must be provided. |
Example
- Asynchronous Mode
- Synchronous Mode
it('copies text out of active element', async () => {
// copies text from an input element
const input = await $('#username')
await input.setValue('anonymous')
await browser.keys(['Meta', 'a'])
await browser.keys(['Meta', 'c'])
});
it('copies text out of active element', () => {
// copies text from an input element
const input = $('#username')
input.setValue('anonymous')
browser.keys(['Meta', 'a'])
browser.keys(['Meta', 'c'])
});
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.