Skip to main content
Glama

get_selected_element

Retrieve details about the currently selected webpage element for browser automation and UI testing on ARM64 devices.

Instructions

Get information about the currently selected element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Implements the core logic for the 'get_selected_element' tool by evaluating JavaScript in the browser to retrieve details of the currently active DOM element (document.activeElement), including tag name, ID, class, text content, value, and a generated selector.
    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:271-278 (registration)
    Registers the 'get_selected_element' tool in the list of available tools returned by ListToolsRequestSchema, 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: {}, }, },
  • Defines the input schema for the 'get_selected_element' tool as an empty object (no required parameters).
    inputSchema: { type: 'object', properties: {}, },
  • Dispatch handler in the CallToolRequestSchema switch statement that routes calls to the getSelectedElement method.
    case 'get_selected_element': return await this.getSelectedElement();

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/nfodor/claude-arm64-browser'

If you have feedback or need assistance with the MCP directory API, please join our Discord server