Skip to main content
Glama

pilot_element_state

Before interacting with an element, confirm its state (visible, enabled, checked, etc.) with a boolean response.

Instructions

Check the current state of an element — whether it is visible, hidden, enabled, disabled, checked, editable, or focused. Use when the user wants to verify an element's condition before interacting with it, check if a button is disabled, confirm a checkbox is checked, or debug why an interaction is failing.

Parameters:

  • ref: Element reference from snapshot (e.g., "@e3") or CSS selector

  • property: The state to check — "visible", "hidden", "enabled", "disabled", "checked", "editable", or "focused"

Returns: Boolean string "true" or "false" indicating the element's state for the requested property.

Errors:

  • "Element not found": The ref is stale. Run pilot_snapshot to get fresh refs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
refYesElement ref or CSS selector
propertyYesState to check

Implementation Reference

  • The async handler function that executes the pilot_element_state tool logic. Checks element state (visible, hidden, enabled, disabled, checked, editable, focused) either via extension or Playwright locator methods.
      async ({ ref, property }) => {
        await bm.ensureBrowser();
        try {
          const ext = bm.getExtension();
          if (ext) {
            const res = await bm.extSend<{ visible: boolean; enabled: boolean; checked: boolean | null; focused: boolean }>('element_state', { ref });
            const stateMap: Record<string, boolean> = {
              visible: res.visible, hidden: !res.visible,
              enabled: res.enabled, disabled: !res.enabled,
              checked: res.checked ?? false, focused: res.focused,
              editable: res.enabled && res.visible,
            };
            return { content: [{ type: 'text' as const, text: String(stateMap[property] ?? false) }] };
          }
          const page = bm.getPage();
          const resolved = await bm.resolveRef(ref);
          const locator = 'locator' in resolved ? resolved.locator : page.locator(resolved.selector);
    
          let result: boolean;
          switch (property) {
            case 'visible':  result = await locator.isVisible(); break;
            case 'hidden':   result = await locator.isHidden(); break;
            case 'enabled':  result = await locator.isEnabled(); break;
            case 'disabled': result = await locator.isDisabled(); break;
            case 'checked':  result = await locator.isChecked(); break;
            case 'editable': result = await locator.isEditable(); break;
            case 'focused':  result = await locator.evaluate((el) => el === document.activeElement); break;
          }
          return { content: [{ type: 'text' as const, text: String(result) }] };
        } catch (err) {
          return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true };
        }
      }
    );
  • Zod schema defining input parameters: ref (string) and property (enum of: visible, hidden, enabled, disabled, checked, editable, focused).
      {
      ref: z.string().describe('Element ref or CSS selector'),
      property: z.enum(['visible', 'hidden', 'enabled', 'disabled', 'checked', 'editable', 'focused']).describe('State to check'),
    },
  • Registration of the 'pilot_element_state' tool via server.tool() within the registerPageTools function. Includes the full description and parameter schema.
      server.tool(
        'pilot_element_state',
        `Check the current state of an element — whether it is visible, hidden, enabled, disabled, checked, editable, or focused.
    Use when the user wants to verify an element's condition before interacting with it, check if a button is disabled, confirm a checkbox is checked, or debug why an interaction is failing.
    
    Parameters:
    - ref: Element reference from snapshot (e.g., "@e3") or CSS selector
    - property: The state to check — "visible", "hidden", "enabled", "disabled", "checked", "editable", or "focused"
    
    Returns: Boolean string "true" or "false" indicating the element's state for the requested property.
    
    Errors:
    - "Element not found": The ref is stale. Run pilot_snapshot to get fresh refs.`,
          {
          ref: z.string().describe('Element ref or CSS selector'),
          property: z.enum(['visible', 'hidden', 'enabled', 'disabled', 'checked', 'editable', 'focused']).describe('State to check'),
        },
        async ({ ref, property }) => {
          await bm.ensureBrowser();
          try {
            const ext = bm.getExtension();
            if (ext) {
              const res = await bm.extSend<{ visible: boolean; enabled: boolean; checked: boolean | null; focused: boolean }>('element_state', { ref });
              const stateMap: Record<string, boolean> = {
                visible: res.visible, hidden: !res.visible,
                enabled: res.enabled, disabled: !res.enabled,
                checked: res.checked ?? false, focused: res.focused,
                editable: res.enabled && res.visible,
              };
              return { content: [{ type: 'text' as const, text: String(stateMap[property] ?? false) }] };
            }
            const page = bm.getPage();
            const resolved = await bm.resolveRef(ref);
            const locator = 'locator' in resolved ? resolved.locator : page.locator(resolved.selector);
    
            let result: boolean;
            switch (property) {
              case 'visible':  result = await locator.isVisible(); break;
              case 'hidden':   result = await locator.isHidden(); break;
              case 'enabled':  result = await locator.isEnabled(); break;
              case 'disabled': result = await locator.isDisabled(); break;
              case 'checked':  result = await locator.isChecked(); break;
              case 'editable': result = await locator.isEditable(); break;
              case 'focused':  result = await locator.evaluate((el) => el === document.activeElement); break;
            }
            return { content: [{ type: 'text' as const, text: String(result) }] };
          } catch (err) {
            return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true };
          }
        }
      );
  • Import of registerPageTools from './page.js' which contains the pilot_element_state tool registration.
    import { registerPageTools } from './page.js';
    import { registerInspectionTools } from './inspection.js';
    import { registerVisualTools } from './visual.js';
Behavior4/5

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

No annotations provided, so description carries full burden. It discloses that it returns a boolean string, lists possible errors, and implies non-destructive read operation. Could mention absence of side effects.

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?

Description is concise and well-structured: purpose, usage, parameters, return, errors. Each sentence adds value with no redundancy.

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

Completeness5/5

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

Given 2 required parameters and no output schema, description fully covers return type, error handling, and parameter usage. No gaps for a simple query tool.

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?

Schema coverage is 100% (baseline 3). Description adds meaning by explaining ref sources (snapshot or CSS selector) and giving usage examples for property, exceeding schema details.

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

Purpose5/5

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

The description clearly states the tool checks element state (visible, hidden, etc.) and lists all possible states. It distinguishes itself from sibling tools like pilot_assert by focusing on querying state rather than asserting conditions.

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

Usage Guidelines4/5

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

The description provides explicit when-to-use scenarios (e.g., verify condition before interaction, debug failure) but does not explicitly state when not to use or suggest alternatives.

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/TacosyHorchata/Pilot'

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