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();
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves information, implying a read-only operation, but doesn't specify what type of information is returned, potential errors (e.g., if no element is selected), or performance considerations. This leaves gaps in understanding how the tool behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with no wasted words. It's front-loaded with the core purpose and efficiently communicates the tool's function without unnecessary detail. This is an excellent example of conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (0 parameters, no output schema, no annotations), the description is adequate but minimal. It states what the tool does but lacks details on return values, error handling, or usage context. For a tool that likely returns structured data about an element, more completeness would be helpful, though the absence of an output schema makes this less critical.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters, and schema description coverage is 100%, so there are no parameters to document. The description doesn't need to add parameter semantics, and it appropriately doesn't mention any. This meets the baseline for tools with no parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get information about the currently selected element.' It uses a specific verb ('Get') and resource ('currently selected element'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from siblings like 'get_content' or 'select', which could have overlapping contexts.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a selected element first), exclusions, or comparisons to sibling tools like 'get_content' or 'select'. Without this, users might struggle to choose the right tool in context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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