Skip to main content
Glama

browser_get_attribute

Extract attribute values from web elements using locator strategies like ID, CSS, or XPath for automated web testing and data retrieval.

Instructions

Gets the value of an attribute from an element

Input Schema

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

Implementation Reference

  • Registers the browser_get_attribute tool with MCP server.tool(), including input schema (locatorSchema + attribute field) and the handler function that creates ElementService and calls getElementAttribute.
    server.tool( 'browser_get_attribute', 'Gets the value of an attribute from an element', { ...locatorSchema, attribute: z.string().describe('Name of the attribute to get'), }, async ({ by, value, attribute, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const elementService = new ElementService(driver); const attrValue = await elementService.getElementAttribute({ by, value, attribute, timeout, }); return { content: [ { type: 'text', text: `Attribute "${attribute}" has value: ${attrValue}`, }, ], }; } catch (e) { return { content: [ { type: 'text', text: `Error getting attribute: ${(e as Error).message}`, }, ], }; } } );
  • Core handler logic in ElementService class: locates the element using findElement and retrieves the specified attribute value using Selenium WebElement.getAttribute()
    async getElementAttribute(params: LocatorParams & { attribute: string }): Promise<string | null> { const element = await this.findElement(params); return element.getAttribute(params.attribute); }
  • Zod schema object for common locator parameters (by, value, timeout), 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