selenium actions API drag and drop not working in chrome
Diagnoses selenium Actions drag-and-drop failures in Chrome. Use it when drag_and_drop silently does nothing or drops in the wrong place. Not for Firefox drag issues or general Actions API questions.
TL;DR
Chrome is picky about the classic drag_and_drop(source, target): it often needs the pointer to actually move in small steps, so build the action chain manually with click_and_hold, several move_by_offset steps, then release. If the app uses HTML5 drag events, even that can fail, and a small JavaScript snippet dispatching dragstart/drop events is the pragmatic fallback. Always scroll the source into view first; an element outside the viewport is the most common silent failure.
The query
selenium actions API drag and drop not working in chromeUse this when
drag_and_dropcompletes without error but nothing moves- Drops land in the wrong position in Chrome
- HTML5 drag-and-drop widgets do not respond to Actions
Not for
- Drag and drop in Firefox or Safari
- File upload via drag and drop onto inputs (use send_keys to the input)
- Touch actions on mobile emulation
Steps
- Scroll the source element into view and verify both source and target are visible and enabled. Expected output: both elements are in the viewport; visibility checks pass.
- Replace the one-shot
drag_and_dropwith a manual chain:click_and_hold(source), 3-5 smallmove_by_offsetsteps toward the target, thenrelease(). Expected output: the drag visibly progresses and the drop registers. - If it still fails, check whether the app listens for HTML5 drag events (many modern widgets do) and fall back to dispatching the events via
execute_script. Expected output: the app's drop handler fires and state updates. - Assert the post-drop state (element order, updated list) rather than just the absence of errors. Expected output: the UI reflects the completed drag and drop.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_fbhMbWVq9hXwMnWc5-WDBg