Task Progress0 of 5 Tasks
0%

Mouse & Keyboard Interactions

Double click, right click, hover, drag and drop, and key combinations. Each element shows its goal beside it, and its task ticks itself the moment your script gets it right.

1.Mouse actions

Double clickTo do
Not double-clicked yet

Single clicks so far: 0

Goal

Double-click the box so it reports success.

Right click (custom context menu)To do
Right-click me
Goal

Right-click the box to open its custom menu, then choose “Copy link”.

Hover to revealTo do

Hover over me

Goal

Hover over the box to reveal its hidden button, then click that button.

Drag and drop (HTML5)To do
Drag Me
Drop Here
Goal

Drag “Drag Me” into the drop zone.

2.Keyboard actions

Key combinationTo do
Awaiting keypress...
Goal

Focus the input and press Ctrl+Shift+K.

About this Mouse & Keyboard page

Mouse and keyboard interaction testing means driving drag, hover, context-click and key-press events from a script instead of a person. In Selenium 4 you use the Actions class, for example dragAndDrop, moveToElement and contextClick. In Playwright you call dragTo, hover, click with button right, and keyboard.press. This page gives you each interaction as a task with a result box.

Screenshot of the Mouse & Keyboard practice page on QA Playground. Drag-and-drop, hover, right-click, and hotkeys.
Mouse & Keyboard: Drag-and-drop, hover, right-click, and hotkeys.

Frequently asked questions

How do you do drag and drop in Selenium 4?

Create an Actions object and call dragAndDrop(source, target).perform(), or chain clickAndHold, moveToElement and release for finer control. If the page uses HTML5 native drag events, the simple call can fail, and you may need clickAndHold with small moves or a JavaScript fallback.

How do you hover over an element in Playwright?

Call await page.locator('selector').hover(). Playwright waits for the element to be visible and stable, scrolls it into view, then moves the mouse over it. Assert on the revealed menu or tooltip with expect(locator).toBeVisible() afterwards.

How do you right-click in Selenium and Playwright?

In Selenium use new Actions(driver).contextClick(element).perform(). In Playwright use locator.click({ button: 'right' }). Both open the page's custom context menu, which you then locate in the DOM like any other element. Native browser menus cannot be automated.

How do you press keyboard shortcuts in automated tests?

In Playwright use page.keyboard.press('Control+S'). In Selenium use Actions.keyDown(Keys.CONTROL).sendKeys('s').keyUp(Keys.CONTROL). In Cypress use cy.get('body').type('{ctrl}s'). Focus the right element first or the page may ignore the keys.

Why does my drag and drop test pass but nothing moves?

The page probably listens for different events than the ones your tool fires. HTML5 drag uses dragstart and drop, while many widgets use mouse or pointer events. Check which one the page uses, then pick dragTo, manual mouse moves, or dispatched DragEvents to match.

Free developer tools on Randomly.online

QA Playground is part of Randomly.online. These tools help while you write and debug tests: