playwright_drag
Drag elements to target locations in browser automation using CSS selectors for source and destination.
Instructions
Drag an element to a target location
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sourceSelector | Yes | CSS selector for the element to drag | |
| targetSelector | Yes | CSS selector for the target location |
Implementation Reference
- src/tools/browser/interaction.ts:260-284 (handler)Core handler implementation for 'playwright_drag' tool. Performs mouse-based drag from sourceSelector to targetSelector using Playwright API.export class DragTool extends BrowserToolBase { /** * Execute the drag tool */ async execute(args: any, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (page) => { const sourceElement = await page.waitForSelector(args.sourceSelector); const targetElement = await page.waitForSelector(args.targetSelector); const sourceBound = await sourceElement.boundingBox(); const targetBound = await targetElement.boundingBox(); if (!sourceBound || !targetBound) { return createErrorResponse("Could not get element positions for drag operation"); } await page.mouse.move(sourceBound.x + sourceBound.width / 2, sourceBound.y + sourceBound.height / 2); await page.mouse.down(); await page.mouse.move(targetBound.x + targetBound.width / 2, targetBound.y + targetBound.height / 2); await page.mouse.up(); return createSuccessResponse(`Dragged element from ${args.sourceSelector} to ${args.targetSelector}`); }); } }
- src/tools.ts:431-441 (schema)Input schema and metadata definition for the 'playwright_drag' tool, used for MCP tool registration.name: "playwright_drag", description: "Drag an element to a target location", inputSchema: { type: "object", properties: { sourceSelector: { type: "string", description: "CSS selector for the element to drag" }, targetSelector: { type: "string", description: "CSS selector for the target location" }, }, required: ["sourceSelector", "targetSelector"], }, },
- src/toolHandler.ts:645-646 (registration)Dispatch case in main tool handler switch statement that routes 'playwright_drag' calls to dragTool.execute().case "playwright_drag": return await dragTool.execute(args, context);
- src/toolHandler.ts:416-416 (registration)Lazy instantiation of DragTool instance during tool initialization.if (!dragTool) dragTool = new DragTool(server);