Skip to main content
Glama

browser_drag_and_drop

Drag and drop web elements between specified source and target locations 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
targetByYesLocator strategy to find target element
targetValueYesValue for the target locator strategy
timeoutNoMaximum time to wait for element in milliseconds
valueYesValue for the locator strategy

Implementation Reference

  • Core handler logic for drag and drop operation using Selenium WebDriver actions API.
    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(); }
  • Registers the browser_drag_and_drop tool with MCP server, defines input schema, and provides wrapper handler delegating to ActionService.
    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}`, }, ], }; } } );
  • Base Zod schema for element locators, spread into the tool's input schema.
    export const locatorSchema = { by: z .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink']) .describe('Locator strategy to find element'), value: z.string().describe('Value for the locator strategy'), timeout: z.number().optional().describe('Maximum time to wait for element in milliseconds'), };

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