October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Drag an Element With the Puppeteer Mouse API

Move to the source, press, move to the target while holding, and release. Learn coordinate handling, dragAndDrop, movement steps, and common failure causes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To drag an element with Puppeteer’s low-level Mouse API, move to a point on the source, press the mouse button, move to a point on the target while keeping the button pressed, and release it. Use viewport-relative main-frame CSS-pixel coordinates; for elements, you can obtain their positions with boundingBox().

Drag an element with mouse coordinates

This runnable example uses locators to find the elements, then their bounding boxes to calculate center points. Adjust the source point if the interface requires dragging from a dedicated handle.

As an Amazon Associate I earn from qualifying purchases.

const sourceBox = await page.locator('[data-testid="source"]').boundingBox();
const targetBox = await page.locator('[data-testid="target"]').boundingBox();

if (!sourceBox || !targetBox) {
  throw new Error('Drag source or target is not in layout');
}

const source = {
  x: sourceBox.x + sourceBox.width / 2,
  y: sourceBox.y + sourceBox.height / 2,
};
const target = {
  x: targetBox.x + targetBox.width / 2,
  y: targetBox.y + targetBox.height / 2,
};

await page.mouse.move(source.x, source.y);
await page.mouse.down();
await page.mouse.move(target.x, target.y, { steps: 10 });
await page.mouse.up();

The source and target selectors are examples; replace them with selectors present on your page. Puppeteer’s interaction guide recommends locators for selecting and interacting with elements. Locators wait for elements and check readiness conditions; the custom mouse sequence gives you coordinate-level control.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

boundingBox() returns a box relative to the main frame, or null when the element is not part of layout. The center-point calculation is a practical default, not a Puppeteer requirement: choose a point inside the actual draggable area. See the boundingBox reference.

Choose between a manual drag and dragAndDrop

Use the mouse sequence for coordinate control

The four calls—move, down, move, up—let you control where the gesture starts and ends. The Mouse class operates in main-frame CSS pixels measured from the viewport’s top-left corner. page.mouse is the Mouse instance for the page.

Use the Mouse dragAndDrop helper for a drag event sequence

For a more compact alternative, use await page.mouse.dragAndDrop(source, target), where source and target are coordinate points. The documented helper performs drag, dragenter, dragover, and drop in sequence. Its optional delay sets the wait between dragover and drop; the documented default is zero. Check the dragAndDrop API reference for the signature matching your installed version.

Do not confuse this helper with page.mouse.drag(start, target). The separate drag API dispatches a drag event and returns drag data; its reference does not describe the complete drag-enter/over/drop sequence.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set movement steps when the path matters

page.mouse.move(x, y, options) moves to a coordinate. Its optional steps value controls the number of intermediate movements between the current position and destination; the documented default is 1. A larger value can help when an application expects movement along a path, but Puppeteer does not promise that any particular step count will make a site’s drag work. See the move reference.

Understand the limits of synthetic mouse events

Puppeteer documents that Mouse API events are synthetic MouseEvents and do not fully replicate normal user mouse behavior. Its Mouse documentation specifically warns that “dragging and selecting text is not possible using page.mouse.” A basic press-and-move sequence therefore may not match a UI that relies on native HTML drag-and-drop behavior or a framework-specific pointer or touch interaction. The dedicated dragAndDrop helper has the documented drag-event sequence, but no universal method is guaranteed to work for every interface.

Troubleshoot a drag that does not take

  • The bounding box is null: the element is not part of layout. Check that it exists, is attached, and is rendered before requesting its box.
  • The gesture starts in the wrong place: use coordinates on the draggable handle or active region rather than assuming the element’s center initiates dragging.
  • The target is missed: confirm both elements are positioned in the viewport when you calculate coordinates. Recalculate boxes if the page layout changes between measurement and interaction.
  • The calls complete but the UI does not change: inspect whether the interface expects a particular drag event sequence or a pointer/touch interaction. Try the documented page.mouse.dragAndDrop helper when a full HTML drag-and-drop sequence is appropriate.
  • The apparent drop is not accepted: verify the resulting DOM or visible application state; successful input calls alone do not establish that the page accepted the drop.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is to capture a page rather than automate a drag gesture, ScreenshotNeo provides a website screenshot API and MCP server. A single GET request can return an image or PDF; it does not perform Puppeteer drag interactions.

cURL example, with the API options documented at ScreenshotNeo’s API documentation:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie banners, popups, and chat widgets before capture. Bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s free plan.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.