Skip to main content
Glama

browser_get_attribute

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

Instructions

Gets the value of an attribute from an element

Input Schema

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

Implementation Reference

  • Registers the 'browser_get_attribute' MCP tool with server.tool(), including inline input schema (extending locatorSchema with attribute) and handler function that instantiates 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 helper method in ElementService that locates the element using findElement and retrieves the specified attribute value via Selenium WebDriver's getAttribute.
    async getElementAttribute(params: LocatorParams & { attribute: string }): Promise<string | null> { const element = await this.findElement(params); return element.getAttribute(params.attribute); }
  • locatorSchema: Zod object defining base input parameters (by: locator strategy, value: string, optional timeout) extended by the tool 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