API …
Playwright lab

Keyboard, mouse & touch

Event loggers for keys, mouse, wheel, pointer drag, touch taps and the clipboard.

Practice tasks

  • Compare locator.fill() with locator.pressSequentially(): count the input and keydown events.
  • Press Control+A, Backspace, Shift+Tab, Enter and ArrowDown with keyboard.press() and read the key log.
  • Open the command palette with ControlOrMeta+K and close it with Escape.
  • Use mouse.move(), mouse.down(), mouse.up() and mouse.wheel() on the pad and assert the counters.
  • Right-click (button: 'right') and double-click (dblclick) the pad.
  • Drag the custom slider handle with mouse.move/down/up or locator.dragTo() and assert the value.
  • Create a context with hasTouch: true, then use locator.tap() and a touch swipe on the touch pad.
  • Grant clipboard permissions, copy text with the button and read it back with navigator.clipboard.readText().

More Playwright lab practice