Skip to main content

Keyboard Interactions

Once you have queried the element you want to interact with, use the keyboard namespace to type within it.

Type a string​

await city.keyboard.type("Orlando");

Type a string, but mask the output​

This is useful if you don't want a password to show up in the test logs.

await password.keyboard.typeMasked("#ydlk42nk!lk3");

Press a key

Press the key down and then let it up, like a user normally would when typing.

await city.keyboard.press("O");

If you want to press a modifer key (like shift or command) together with your key you can do so like this:

await element.keyboard.press(["Meta", "K"]);

The "Meta" keyword here matches the appropriate command key on both Windows and Mac.

Key down and up

The same syntax as press but down holds the key down continally. It will continue to be pressed until you call up.

await element.keyboard.down("a");
await sleep(1000);
await element.keyboard.up("a");

Select All​

Control/Command+A

await element.keyboard.selectAll();

Copy​

Control/Command+C

await element.keyboard.copy();

Cut​

Control/Command+X

await element.keyboard.cut();

Paste​

Control/Command+V

await element.keyboard.paste();

Backspace​

await element.keyboard.backspace();

Enter​

await element.keyboard.enter();

Delete​

await element.keyboard.delete();

Escape​

await element.keyboard.escape();

Tab​

await element.keyboard.tab();

Arrow Up​

await element.keyboard.arrowUp();

Arrow Down​

await element.keyboard.arrowDown();

Arrow Left​

await element.keyboard.arrowLeft());

Arrow Right​

await element.keyboard.arrowRight();

Press Special Keys​

We have some easy methods for common ones like backspace() but this method gives you type-safety and intellisense to know what strings are valid special keys. So this can do anything like PageUp, Home, End, F1-F12, CapsLock, etc.

await element.keyboard.pressSpecial("PageDown");