How to Test Drag and Drop (and Why It Fails)
Synthetic mouse events never trigger the HTML5 drag API. Diagnose which drag system a page uses, then test it with Playwright, Selenium or Cypress.
One gesture, two unrelated event systems — a test built for the wrong one reports success while nothing moves.
A drag is the one interaction where a manual click-through proves almost nothing about the automated one. Browsers run two unrelated event systems under the same gesture, and a test built for the wrong one silently no-ops: every command reports success while nothing moves. Before choosing a tool strategy, work out which system the widget listens to.
The two event systems
The first family is the HTML5 drag-and-drop API. The source element carries draggable="true"; the gesture produces a real event sequence — dragstart, dragenter, dragover, drop, dragend — and the payload travels in a DataTransfer object that drop handlers read with getData(). Dropping without that payload is not the same gesture: an app that validates it rejects the drop.
The second family is plain pointer scripting: mousedown, mousemove, mouseup (or their pointer-event equivalents). Custom sortable lists, sliders and canvas tools use this because it gives them full control of the gesture. There is no DataTransfer and no drop event; the handlers watch the cursor themselves.
The diagnostic is one look at the source element: if it has draggable="true", the tool must produce the HTML5 drag sequence. Synthetic mouse steps never trigger it — this is the most common reason a drag test fails while the same gesture works by hand.
What each framework actually does
Playwright has built-in awareness of both systems. locator.dragTo() and page.dragAndDrop() drive the HTML5 sequence when the source is draggable and plain mouse events otherwise. Raw mouse.down() / mouse.move() / mouse.up() steps drive only the pointer family — fine for a slider, useless against a drop zone.
Selenium's Actions API emits WebDriver mouse events, and whether the browser promotes them into the HTML5 sequence depends on the driver. In Chromium the dragstart/dragover/drop chain typically never starts: the test finishes green and the drop handler is never called. The established workaround is dispatching synthetic DragEvents from JavaScript with a constructed DataTransfer — a trade of browser realism for determinism that is worth making consciously.
Cypress has the same gap from the other direction. .trigger('mousedown') fires standalone synthetic events with no continuity between them and no real DataTransfer, so a drop handler reading the payload gets whatever was faked into the event. The cypress-real-events plugin performs Chromium-level input for the pointer family; for HTML5 DnD the DataTransfer shim remains the way.
Assert the committed outcome
Whichever route you take, assert state that survives the gesture: the destination column's header text, the reordered list rendered as text, a counter incremented on drop. Mid-gesture signals — dragover highlight classes, cursor styles — are implementation details a redesign deletes while the behavior contract survives.
Practice both sides
The Drag and Drop challenge is native HTML5 DnD. The ring carries a text/plain payload the drop handler validates, so a shim that drops without data fails honestly — exactly like a real app that trusts its payload. The second exercise reorders the list and mirrors the result as text, which gives the assertion something stable to read.
import { test, expect } from '@playwright/test';
test('carrying the ring updates the destination column', async ({ page }) => {
await page.goto('https://funui.dev/challenges/drag-and-drop');
await page.getByTestId('dnd-ring').dragTo(page.getByTestId('dnd-column-b'));
await expect(page.getByTestId('dnd-column-b')).toContainText('ring here');
});
test('reordering updates the printed march order', async ({ page }) => {
await page.goto('https://funui.dev/challenges/drag-and-drop');
const members = page.getByTestId('dnd-member');
await members.nth(0).dragTo(members.nth(3));
await expect(page.getByTestId('dnd-order')).toHaveText(
'Samgar, Gandor the Grey, Aravorn, Frodmund, Gimlin, Legolan'
);
});
Continue with Hovers and the Slider for the pointer-event family, and with the locator anti-patterns article for keeping the locators in these examples stable.
Keep reading
- Practice this topic
- Playwright Locators and Waits: A Practical Guide
- Testing iframes and Shadow DOM with Playwright
- QA Interview Bug Hunts: A Playwright Walkthrough
- Five Stable-Locator Anti-Patterns
- Network Idle Is Not “Ready”
- Testing a Custom Combobox Without Sleeps
- Deterministic Test Data Without Boring Tests
- Visibility vs. Presence: The Wait Condition Bug
Updated
Fun UI Playground — all challenges, bug hunts, getting started, glossary, about.