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'] } },

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