get_selected_element
Retrieve details about the currently selected web element during browser automation on ARM64 devices, enabling precise UI testing and interaction tracking.
Instructions
Get information about the currently selected element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.js:812-840 (handler)The main handler function for the 'get_selected_element' tool. It ensures Chromium is running, evaluates JavaScript to retrieve details of the currently active DOM element (tagName, id, className, textContent, value, selector), parses the result, and returns a formatted text response.async getSelectedElement() { await this.ensureChromium(); const result = await this.sendCDPCommand('Runtime.evaluate', { expression: ` const activeElement = document.activeElement; if (activeElement && activeElement !== document.body) { JSON.stringify({ tagName: activeElement.tagName, id: activeElement.id, className: activeElement.className, textContent: activeElement.textContent?.substring(0, 100), value: activeElement.value || null, selector: activeElement.id ? \`#\${activeElement.id}\` : activeElement.className ? \`.\${activeElement.className.split(' ')[0]}\` : activeElement.tagName.toLowerCase() }); } else { null; } `, returnByValue: true }); const selectedElement = result.result?.value ? JSON.parse(result.result.value) : null; return { content: [{ type: 'text', text: selectedElement ? JSON.stringify(selectedElement, null, 2) : 'No element currently selected' }], }; }
- index.js:272-278 (registration)Registers the 'get_selected_element' tool in the MCP server's list of available tools, specifying its name, description, and empty input schema (no parameters required).name: 'get_selected_element', description: 'Get information about the currently selected element', inputSchema: { type: 'object', properties: {}, }, },
- index.js:274-277 (schema)Defines the input schema for the 'get_selected_element' tool as an empty object, indicating no input parameters are required.inputSchema: { type: 'object', properties: {}, },
- index.js:377-378 (helper)Switch case in the CallToolRequestHandler that routes calls to the 'get_selected_element' tool to its handler method.case 'get_selected_element': return await this.getSelectedElement();