Skip to main content
Glama

browser_find_elements

Locate multiple web elements using Selenium WebDriver with strategies like CSS, XPath, or ID for browser automation and testing.

Instructions

Find multiple elements

Input Schema

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

Implementation Reference

  • Registration of the 'browser_find_elements' MCP tool, including inline handler function that uses ElementService to find elements and returns a success/error message.
    server.tool( 'browser_find_elements', 'Find multiple elements', { ...locatorSchema }, async ({ by, value, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const elementService = new ElementService(driver); const elements = await elementService.findElements({ by, value, timeout, }); return { content: [{ type: 'text', text: `Found ${elements.length} elements` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error finding elements: ${(e as Error).message}`, }, ], }; } } );
  • Zod schema definition for locator parameters (by, value, timeout) used in the browser_find_elements tool.
    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'), };
  • ElementService.findElements method: core logic to wait for and find multiple elements using Selenium WebDriver.
    async findElements(params: LocatorParams): Promise<WebElement[]> { const locator = LocatorFactory.createLocator(params.by, params.value); await this.driver.wait(until.elementsLocated(locator), params.timeout || 15000); return this.driver.findElements(locator); }
  • LocatorFactory.createLocator: utility to create Selenium By locator objects based on strategy.
    static createLocator(by: LocatorStrategy, value: string): Locator { switch (by.toLowerCase()) { case 'id': return By.id(value); case 'css': return By.css(value); case 'xpath': return By.xpath(value); case 'name': return By.name(value); case 'tag': return By.css(value); case 'class': return By.className(value); case 'link': return By.linkText(value); case 'partialLink': return By.partialLinkText(value); default: throw new Error(`Unsupported locator strategy: ${by}`); } }

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