drag-element
Drag a web element from one location to another using CSS selectors to automate browser interactions through the AdsPower LocalAPI MCP Server.
Instructions
Drag the element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | The selector of the element to drag, find from the page source code | |
| targetSelector | Yes | The selector of the element to drag to, find from the page source code |
Implementation Reference
- src/handlers/automation.ts:137-160 (handler)The main handler function for the 'drag-element' tool. It uses Playwright to locate source and target elements by selectors, computes their bounding boxes, and simulates a mouse drag from source to target.async dragElement({ selector, targetSelector }: DragElementParams) { browser.checkConnected(); const sourceElement = await browser.pageInstance!.waitForSelector(selector); const targetElement = await browser.pageInstance!.waitForSelector(targetSelector); const sourceBound = await sourceElement.boundingBox(); const targetBound = await targetElement.boundingBox(); if (!sourceBound || !targetBound) { return `Could not get element positions for drag operation`; } await browser.pageInstance!.mouse.move( sourceBound.x + sourceBound.width / 2, sourceBound.y + sourceBound.height / 2 ); await browser.pageInstance!.mouse.down(); await browser.pageInstance!.mouse.move( targetBound.x + targetBound.width / 2, targetBound.y + targetBound.height / 2 ); await browser.pageInstance!.mouse.up(); return `Dragged element with selector: ${selector} to ${targetSelector} successfully`; }
- src/types/schemas.ts:213-216 (schema)Zod schema defining input parameters for the drag-element tool: selector for the element to drag and targetSelector for the drop target.dragElementSchema: z.object({ selector: z.string().describe('The selector of the element to drag, find from the page source code'), targetSelector: z.string().describe('The selector of the element to drag to, find from the page source code'), }).strict(),
- src/utils/toolRegister.ts:89-90 (registration)Tool registration call that associates the name 'drag-element' with its description, schema, and wrapped handler function.server.tool('drag-element', 'Drag the element', schemas.dragElementSchema.shape, wrapHandler(automationHandlers.dragElement));