Skip to main content
Glama

browser_drag_and_drop

Automate drag-and-drop interactions between web elements using Selenium WebDriver for browser automation and testing workflows.

Instructions

Perform drag and drop between two elements

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
byYesLocator strategy to find element
valueYesValue for the locator strategy
timeoutNoMaximum time to wait for element in milliseconds
targetByYesLocator strategy to find target element
targetValueYesValue for the target locator strategy

Implementation Reference

  • MCP tool handler that receives parameters and calls ActionService.dragAndDrop
    async ({ by, value, targetBy, targetValue, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.dragAndDrop({ by, value, timeout }, { by: targetBy, value: targetValue, timeout }); return { content: [{ type: 'text', text: 'Drag and drop completed' }], }; } catch (e) { return { content: [ { type: 'text', text: `Error performing drag and drop: ${(e as Error).message}`, }, ], }; } }
  • Input schema definition for the browser_drag_and_drop tool using Zod
    { ...locatorSchema, targetBy: z .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink']) .describe('Locator strategy to find target element'), targetValue: z.string().describe('Value for the target locator strategy'), },
  • Registration of the browser_drag_and_drop tool with McpServer
    server.tool( 'browser_drag_and_drop', 'Perform drag and drop between two elements', { ...locatorSchema, targetBy: z .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink']) .describe('Locator strategy to find target element'), targetValue: z.string().describe('Value for the target locator strategy'), }, async ({ by, value, targetBy, targetValue, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.dragAndDrop({ by, value, timeout }, { by: targetBy, value: targetValue, timeout }); return { content: [{ type: 'text', text: 'Drag and drop completed' }], }; } catch (e) { return { content: [ { type: 'text', text: `Error performing drag and drop: ${(e as Error).message}`, }, ], }; } } );
  • Core implementation of drag and drop using Selenium WebDriver actions
    async dragAndDrop(sourceParams: LocatorParams, targetParams: LocatorParams): Promise<void> { const sourceLocator = LocatorFactory.createLocator(sourceParams.by, sourceParams.value); const targetLocator = LocatorFactory.createLocator(targetParams.by, targetParams.value); const sourceElement = await this.driver.wait(until.elementLocated(sourceLocator), sourceParams.timeout || 15000); const targetElement = await this.driver.wait(until.elementLocated(targetLocator), targetParams.timeout || 15000); const actions = this.driver.actions({ bridge: true }); await actions.dragAndDrop(sourceElement, targetElement).perform(); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pshivapr/selenium-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server