|
| 1 | +--- |
| 2 | +sidebar_position: 4 |
| 3 | +--- |
| 4 | + |
| 5 | +# dragAndDrop |
| 6 | + |
| 7 | +Drag and drop an element from a source location to a target location. |
| 8 | + |
| 9 | +## Syntax |
| 10 | + |
| 11 | +```json |
| 12 | +{ |
| 13 | + "dragAndDrop": "source_element" |
| 14 | +} |
| 15 | +``` |
| 16 | + |
| 17 | +```json |
| 18 | +{ |
| 19 | + "dragAndDrop": { |
| 20 | + "source": "source_element", |
| 21 | + "target": "target_element", |
| 22 | + "duration": 1000 |
| 23 | + } |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +## Properties |
| 28 | + |
| 29 | +| Property | Type | Description | Default | |
| 30 | +| :-- | :-- | :-- | :-- | |
| 31 | +| `source` | string or object | **Required.** The element to drag. Can be display text, CSS selector, XPath selector, or a detailed element object. | | |
| 32 | +| `target` | string or object | **Required.** The target location to drop the element. Can be display text, CSS selector, XPath selector, or a detailed element object. | | |
| 33 | +| `duration` | integer | Duration of the drag operation in milliseconds. | `1000` | |
| 34 | + |
| 35 | +### Element specification |
| 36 | + |
| 37 | +Both `source` and `target` can be specified as: |
| 38 | + |
| 39 | +- **String**: Display text, CSS selector, or regex pattern (enclosed in forward slashes) |
| 40 | +- **Object**: Detailed element specification with the following properties: |
| 41 | + |
| 42 | +| Property | Type | Description | Default | |
| 43 | +| :-- | :-- | :-- | :-- | |
| 44 | +| `elementText` | string | Display text or regex pattern (enclosed in forward slashes) of the element. | | |
| 45 | +| `selector` | string | CSS selector or XPath selector of the element. | | |
| 46 | +| `timeout` | integer | Maximum duration in milliseconds to wait for the element to exist. | `5000` | |
| 47 | + |
| 48 | +When using the object format, you must specify either `elementText` or `selector` (or both). If both are specified, the element must match both criteria. |
| 49 | + |
| 50 | +## Examples |
| 51 | + |
| 52 | +### Basic drag and drop |
| 53 | + |
| 54 | +Drag an element with text "Table" to an element with ID "canvas": |
| 55 | + |
| 56 | +```json |
| 57 | +{ |
| 58 | + "dragAndDrop": { |
| 59 | + "source": "Table", |
| 60 | + "target": "#canvas" |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### Drag and drop with CSS selectors |
| 66 | + |
| 67 | +Drag a draggable block to a drop zone with custom duration: |
| 68 | + |
| 69 | +```json |
| 70 | +{ |
| 71 | + "dragAndDrop": { |
| 72 | + "source": ".draggable-block", |
| 73 | + "target": ".drop-zone", |
| 74 | + "duration": 2000 |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +### Detailed element specification |
| 80 | + |
| 81 | +Drag a widget with specific text to a design canvas: |
| 82 | + |
| 83 | +```json |
| 84 | +{ |
| 85 | + "dragAndDrop": { |
| 86 | + "source": { |
| 87 | + "selector": ".widget", |
| 88 | + "elementText": "Data Table" |
| 89 | + }, |
| 90 | + "target": { |
| 91 | + "selector": "#design-canvas" |
| 92 | + }, |
| 93 | + "duration": 500 |
| 94 | + } |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +### Using regex patterns |
| 99 | + |
| 100 | +Drag any widget item to a canvas using regex patterns: |
| 101 | + |
| 102 | +```json |
| 103 | +{ |
| 104 | + "dragAndDrop": { |
| 105 | + "source": "/Widget Item.*/", |
| 106 | + "target": "#canvas" |
| 107 | + } |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +### Complex element matching |
| 112 | + |
| 113 | +Drag a button with regex text pattern to a drop zone: |
| 114 | + |
| 115 | +```json |
| 116 | +{ |
| 117 | + "dragAndDrop": { |
| 118 | + "source": { |
| 119 | + "selector": ".draggable", |
| 120 | + "elementText": "/Button [0-9]+/" |
| 121 | + }, |
| 122 | + "target": { |
| 123 | + "elementText": "/Drop Zone.*/" |
| 124 | + } |
| 125 | + } |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +## Notes |
| 130 | + |
| 131 | +- The `dragAndDrop` action simulates mouse drag-and-drop interactions |
| 132 | +- Both source and target elements must be visible and interactable |
| 133 | +- The `duration` property controls how long the drag operation takes, which can be useful for animations or visual feedback |
| 134 | +- If elements are not found within the specified timeout, the step will fail |
| 135 | +- Regex patterns must be enclosed in forward slashes (e.g., `/pattern/`) |
| 136 | +- The action waits for both source and target elements to exist before performing the drag operation |
0 commit comments