dragAndDrop
Move elements between locations in web interfaces by specifying source and target selectors for automated browser interactions.
Instructions
Drag and drop from one element to another
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sourceSelector | Yes | ||
| targetSelector | Yes |
Implementation Reference
- src/controllers/playwright.ts:635-649 (handler)The core implementation of the dragAndDrop tool, using Playwright locators to drag from sourceSelector to targetSelector.
async dragAndDrop(sourceSelector: string, targetSelector: string): Promise<void> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } this.log('Performing drag and drop', { sourceSelector, targetSelector }); const sourceLocator = this.state.page.locator(sourceSelector); const targetLocator = this.state.page.locator(targetSelector); await sourceLocator.dragTo(targetLocator); this.log('Drag and drop complete'); } catch (error: any) { console.error('Drag and drop error:', error); throw new BrowserError('Failed to drag and drop', 'Check if both selectors exist and are interactable'); } } - src/server.ts:282-293 (schema)The input schema and metadata definition for the dragAndDrop tool.
const DRAG_AND_DROP_TOOL: Tool = { name: "dragAndDrop", description: "Drag and drop from one element to another", inputSchema: { type: "object", properties: { sourceSelector: { type: "string" }, targetSelector: { type: "string" } }, required: ["sourceSelector", "targetSelector"] } }; - src/server.ts:537-537 (registration)Registration of the dragAndDrop tool in the tools dictionary provided to the MCP server.
dragAndDrop: DRAG_AND_DROP_TOOL, - src/server.ts:808-819 (helper)The dispatch logic in the MCP callTool handler that validates parameters and invokes the controller's dragAndDrop method.
case 'dragAndDrop': { if (!args.sourceSelector || !args.targetSelector) { return { content: [{ type: "text", text: "Source and target selectors are required" }], isError: true }; } await playwrightController.dragAndDrop(args.sourceSelector as string, args.targetSelector as string); return { content: [{ type: "text", text: "Drag and drop completed successfully" }] }; }