Skip to main content
Glama

wait_for_element

Waits for a web element to reach a specified state (visible, hidden, attached, detached) using a CSS selector within a defined timeout, ensuring proper web automation and interaction timing.

Instructions

Wait for an element to appear or disappear

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for the element
stateNoState to wait forvisible
timeoutNoTimeout in milliseconds

Implementation Reference

  • Handler for the 'wait_for_element' tool. Parses input using WaitForElementSchema and uses Playwright's page.waitForSelector to wait for the element matching the selector to reach the specified state (default: visible) within the timeout period.
    case 'wait_for_element': {
      if (!currentPage) {
        throw new Error('No browser page available. Launch a browser first.');
      }
    
      const params = WaitForElementSchema.parse(args);
      await currentPage.waitForSelector(params.selector, {
        timeout: params.timeout,
        state: params.state as any
      });
    
      return {
        content: [
          {
            type: 'text',
            text: `Element ${params.selector} is now ${params.state}`
          }
        ]
      };
    }
  • Zod schema defining the input parameters for the wait_for_element tool: selector (required CSS selector), timeout (default 30s), state (attached/detached/visible/hidden, default visible).
    const WaitForElementSchema = z.object({
      selector: z.string(),
      timeout: z.number().default(30000),
      state: z.enum(['attached', 'detached', 'visible', 'hidden']).default('visible')
    });
  • src/index.ts:256-280 (registration)
    Tool registration in the ListTools response, including name, description, and inputSchema matching the Zod schema.
    {
      name: 'wait_for_element',
      description: 'Wait for an element to appear or disappear',
      inputSchema: {
        type: 'object',
        properties: {
          selector: {
            type: 'string',
            description: 'CSS selector for the element'
          },
          timeout: {
            type: 'number',
            default: 30000,
            description: 'Timeout in milliseconds'
          },
          state: {
            type: 'string',
            enum: ['attached', 'detached', 'visible', 'hidden'],
            default: 'visible',
            description: 'State to wait for'
          }
        },
        required: ['selector']
      }
    },
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 mentions waiting for appearance/disappearance but lacks details on error handling (e.g., what happens on timeout), performance implications (e.g., blocking nature), or side effects. This is a significant gap for a tool that interacts with dynamic web elements.

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, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded and wastes no space, making it easy to parse quickly.

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

Completeness2/5

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

Given the complexity of interacting with web elements and the lack of annotations and output schema, the description is insufficient. It doesn't cover behavioral aspects like what is returned (e.g., success/failure, element details), error conditions, or integration with sibling tools in a browser automation context.

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

Parameters3/5

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

The schema description coverage is 100%, with clear documentation for all parameters (selector, state, timeout). The description adds no additional meaning beyond what the schema provides, such as explaining the practical use of states or timeout behavior. Baseline 3 is appropriate since the schema does the heavy lifting.

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 with a specific verb ('wait for') and resource ('an element'), specifying the action of waiting for appearance or disappearance. However, it doesn't explicitly differentiate from sibling tools like 'check_scrollability' or 'get_element_text', which might also involve element interaction but serve different purposes.

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 scenarios where waiting is necessary (e.g., after navigation or dynamic content loading) or when other tools like 'get_element_text' might be more appropriate for immediate checks. No exclusions or prerequisites are stated.

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

Related 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/Wladastic/mcp-browser-server'

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