Skip to main content
Glama

browser_wait_for_element

Waits for a web element to appear on a page using specified locator strategy and timeout, enabling reliable automation of dynamic content interactions.

Instructions

Wait for an element to be present

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
byYesLocator strategy to find element
valueYesValue for the locator strategy
timeoutYesTimeout in milliseconds

Implementation Reference

  • Registers the browser_wait_for_element MCP tool, including input schema (locator + timeout) and thin handler that delegates to ActionService.waitForElement after getting driver from stateManager.
    server.tool(
      'browser_wait_for_element',
      'Wait for an element to be present',
      {
        ...locatorSchema,
        timeout: z.number().describe('Timeout in milliseconds'),
      },
      async ({ by, value, timeout = 15000 }) => {
        try {
          const driver = stateManager.getDriver();
          const actionService = new ActionService(driver);
          await actionService.waitForElement({ by, value, timeout });
          return {
            content: [{ type: 'text', text: `Waited for element: ${value}` }],
          };
        } catch (e) {
          return {
            content: [
              {
                type: 'text',
                text: `Error waiting for element: ${(e as Error).message}`,
              },
            ],
          };
        }
      }
    );
  • Core implementation of waiting for element: uses LocatorFactory to create Selenium locator and driver.wait with until.elementLocated.
    async waitForElement(params: LocatorParams): Promise<WebElement> {
      const locator = LocatorFactory.createLocator(params.by, params.value);
      return this.driver.wait(until.elementLocated(locator), params.timeout || 15000);
    }
  • locatorSchema defines the base input parameters (by, value, optional timeout) using Zod, spread into the tool schema.
    export const locatorSchema = {
      by: z
        .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink'])
        .describe('Locator strategy to find element'),
      value: z.string().describe('Value for the locator strategy'),
      timeout: z.number().optional().describe('Maximum time to wait for element in milliseconds'),
    };
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool waits for an element, implying it may block execution until the element appears or timeout occurs, but doesn't detail what happens on success (e.g., returns element reference) or failure (e.g., throws error), nor does it mention side effects like implicit waits or performance impacts. This is a significant gap for a tool with potential blocking behavior.

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 any wasted words. It's appropriately sized and front-loaded, making it easy to understand at a glance.

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 tool's complexity (involving waiting behavior with a timeout) and lack of annotations or output schema, the description is incomplete. It doesn't explain the return value (e.g., whether it returns the element or just success status), error handling, or how it interacts with other browser tools. For a synchronization tool, this leaves critical gaps for an AI agent.

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 input schema has 100% description coverage, providing clear documentation for all three parameters ('by', 'value', 'timeout'). The description adds no additional meaning beyond the schema, such as explaining how 'timeout' affects waiting behavior or default values. Baseline score of 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 'Wait for an element to be present' clearly states the tool's function with a specific verb ('wait for') and resource ('element'), distinguishing it from siblings like 'browser_find_element' which likely retrieves elements immediately. However, it doesn't explicitly differentiate from similar tools (e.g., 'browser_element_is_displayed'), keeping it from a perfect score.

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?

No guidance is provided on when to use this tool versus alternatives. For example, it doesn't specify if this is for synchronization in automation scripts or how it differs from 'browser_find_element' (which might fail immediately if not found). The description implies usage but offers no explicit context or exclusions.

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/pshivapr/selenium-mcp'

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