keys
Overview
Use the keys
command to send a sequence of key presses to the active element.
You can also use symbols like “Left Arrow” or “Right Arrow”. They will be automatically transformed to the corresponding unicode characters. You can see all supported characters here.
Modifiers such as Ctrl
, Shift
, Alt
, and Meta
remain pressed until you release them by calling the function again. However, modifying clicks requires using the performActions method from the WebDriver Actions API.
Usage
await browser.keys(value);
Command Parameters
Name | Type | Description |
value | String or String[] | The sequence of keys to type. |
Usage Examples
it("copies text out of active element", async ({ browser }) => {
// copy text from input element
await browser.$("#username").setValue("anonymous");
await browser.keys(["Meta", "a"]);
await browser.keys(["Meta", "c"]);
});
References
We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.