browser_get_element_attribute
Retrieve attribute values from web page elements using selectors for automated browser testing and data extraction.
Instructions
Get element attribute value
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instanceId | Yes | Instance ID | |
| selector | Yes | Element selector | |
| attribute | Yes | Attribute name | |
| timeout | No | Timeout in milliseconds |
Implementation Reference
- src/tools.ts:868-888 (handler)The main handler function for the 'browser_get_element_attribute' tool. It retrieves the browser instance, locates the element using the selector, fetches the specified attribute value using Playwright's page.getAttribute method, and returns the result or error.private async getElementAttribute(instanceId: string, selector: string, attribute: string, timeout: number): Promise<ToolResult> { const instance = this.browserManager.getInstance(instanceId); if (!instance) { return { success: false, error: `Instance ${instanceId} not found` }; } try { const value = await instance.page.getAttribute(selector, attribute, { timeout }); return { success: true, data: { selector, attribute, value }, instanceId }; } catch (error) { return { success: false, error: `Get element attribute failed: ${error instanceof Error ? error.message : error}`, instanceId }; } }
- src/tools.ts:330-356 (registration)The tool registration in getTools(), defining the name, description, and inputSchema for 'browser_get_element_attribute'.{ name: 'browser_get_element_attribute', description: 'Get element attribute value', inputSchema: { type: 'object', properties: { instanceId: { type: 'string', description: 'Instance ID' }, selector: { type: 'string', description: 'Element selector', }, attribute: { type: 'string', description: 'Attribute name', }, timeout: { type: 'number', description: 'Timeout in milliseconds', default: 30000 } }, required: ['instanceId', 'selector', 'attribute'] } },
- src/tools.ts:559-560 (registration)The dispatch case in executeTools() that routes calls to the getElementAttribute handler.case 'browser_get_element_attribute': return await this.getElementAttribute(args.instanceId, args.selector, args.attribute, args.timeout || 30000);
- src/tools.ts:333-355 (schema)The input schema defining parameters for the tool: instanceId, selector, attribute (required), and optional timeout.inputSchema: { type: 'object', properties: { instanceId: { type: 'string', description: 'Instance ID' }, selector: { type: 'string', description: 'Element selector', }, attribute: { type: 'string', description: 'Attribute name', }, timeout: { type: 'number', description: 'Timeout in milliseconds', default: 30000 } }, required: ['instanceId', 'selector', 'attribute'] }