|
| 1 | +--- |
| 2 | +title: dragAndDrop |
| 3 | +layout: default |
| 4 | +nav_order: 3 |
| 5 | +parent: Actions |
| 6 | +grand_parent: Tests |
| 7 | +description: Drag an element from a source location to a target location. |
| 8 | +--- |
| 9 | + |
| 10 | +# dragAndDrop |
| 11 | + |
| 12 | +The `dragAndDrop` action allows you to drag an element and drop it at a target location. This is useful for testing drag-and-drop interfaces, reordering lists, moving items between containers, and other interactive UI elements. |
| 13 | + |
| 14 | +The `dragAndDrop` action requires both a source and target element, which can be specified using element text, CSS/XPath selectors, or detailed objects with additional configuration options. |
| 15 | + |
| 16 | +## Use Cases |
| 17 | + |
| 18 | +The `dragAndDrop` action is particularly useful for testing: |
| 19 | + |
| 20 | +- **Kanban boards**: Moving tasks between different status columns |
| 21 | +- **File uploads**: Dragging files from desktop to upload areas |
| 22 | +- **List reordering**: Changing the order of items in sortable lists |
| 23 | +- **Dashboard widgets**: Rearranging components on customizable dashboards |
| 24 | +- **Form builders**: Moving form elements between different sections |
| 25 | +- **Shopping carts**: Adding items by dragging them to the cart area |
| 26 | + |
| 27 | +## Properties |
| 28 | + |
| 29 | +The `dragAndDrop` action requires an object with the following properties: |
| 30 | + |
| 31 | +- `source`: (Required) The element to drag from. Can be a string (element text or selector) or a detailed object. |
| 32 | +- `target`: (Required) The element to drop onto. Can be a string (element text or selector) or a detailed object. |
| 33 | + |
| 34 | +### Source and Target Element Properties |
| 35 | + |
| 36 | +When using detailed objects for `source` or `target`, you can specify: |
| 37 | + |
| 38 | +- `elementText`: (Optional) Display text of the element. If combined with `selector`, the element must match both the text and the selector. |
| 39 | +- `selector`: (Optional) CSS or XPath selector of the element. If combined with `elementText`, the element must match both the text and the selector. |
| 40 | +- `timeout`: (Optional) Maximum duration in milliseconds to wait for this specific element to exist. |
| 41 | + |
| 42 | + |
| 43 | +> For comprehensive options, see the full [`dragAndDrop`](/docs/references/schemas/draganddrop) reference. |
| 44 | +
|
| 45 | +## Examples |
| 46 | + |
| 47 | +Here are several ways you might use the `dragAndDrop` action: |
| 48 | + |
| 49 | +### Drag and drop using selectors or element text |
| 50 | + |
| 51 | +```json |
| 52 | +{ |
| 53 | + "tests": [ |
| 54 | + { |
| 55 | + "steps": [ |
| 56 | + { |
| 57 | + "description": "Drag 'Item 1' and drop it onto 'Drop Zone'", |
| 58 | + "dragAndDrop": { |
| 59 | + "source": "#source-list .draggable-item:first-child", |
| 60 | + "target": "Drop Zone" |
| 61 | + } |
| 62 | + } |
| 63 | + ] |
| 64 | + } |
| 65 | + ] |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +### Drag and drop with detailed element objects |
| 70 | + |
| 71 | +```json |
| 72 | +{ |
| 73 | + "tests": [ |
| 74 | + { |
| 75 | + "steps": [ |
| 76 | + { |
| 77 | + "description": "Drag a specific task to a different column", |
| 78 | + "dragAndDrop": { |
| 79 | + "source": { |
| 80 | + "selector": ".task-card", |
| 81 | + "elementText": "Complete documentation" |
| 82 | + }, |
| 83 | + "target": { |
| 84 | + "selector": ".column", |
| 85 | + "elementText": "In Progress" |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + ] |
| 90 | + } |
| 91 | + ] |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## Related Actions |
| 96 | + |
| 97 | +- [`click`](/docs/get-started/actions/click): Click elements to interact with them |
| 98 | +- [`find`](/docs/get-started/actions/find): Locate elements before performing other actions |
| 99 | +- [`wait`](/docs/get-started/actions/wait): Add delays for animations to complete |
0 commit comments