Skip to main content

dragAndDrop

Overview

Use the dragAndDrop command to drag an element to a specified target element or position.

Usage

await browser.$(selector).dragAndDrop(target, { duration });

Command Parameters

NameTypeDescription
targetElement or DragAndDropCoordinateTarget element or an object with x and y coordinates.
durationNumberTimeout for dragging the element (drag operation).

Usage Examples

it("should demonstrate the dragAndDrop command", async ({ browser }) => {
const elem = await browser.$("#someElem");
const target = await browser.$("#someTarget");

// perform drag and drop to another element
await elem.dragAndDrop(target);

// perform drag and drop relative to the current position
await elem.dragAndDrop({ x: 100, y: 200 });
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.