drag-element
Simulate dragging a specified webpage element to a target location using element selectors. Part of AdsPower LocalAPI MCP Server, enabling precise browser interaction for automation.
Instructions
Drag the element
Input 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 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"selector": {
"description": "The selector of the element to drag, find from the page source code",
"type": "string"
},
"targetSelector": {
"description": "The selector of the element to drag to, find from the page source code",
"type": "string"
}
},
"required": [
"selector",
"targetSelector"
],
"type": "object"
}
Implementation Reference
- src/handlers/automation.ts:137-160 (handler)The main handler function for the 'drag-element' tool. It performs a drag operation by moving the mouse to the center of the source element, pressing down, moving to the target element's center, and releasing.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 'drag-element': selector (source element) and targetSelector (destination element).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)Registers the 'drag-element' tool with the MCP server using the defined schema and wrapped handler from automationHandlers.server.tool('drag-element', 'Drag the element', schemas.dragElementSchema.shape, wrapHandler(automationHandlers.dragElement));