Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

waitForSelector

Waits for a specific HTML element to appear on a webpage before proceeding, ensuring reliable automation by synchronizing with page loading and dynamic content.

Instructions

Wait for a specific selector to appear on the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYes
timeoutNoTimeout in milliseconds (default: 30000)

Implementation Reference

  • The core handler function implementing waitForSelector using Playwright's page.waitForSelector method, with error handling and logging.
    async waitForSelector(selector: string, timeout: number = 30000): Promise<void> {
      try {
        if (!this.isInitialized() || !this.state.page) {
          throw new Error('Browser not initialized');
        }
        this.log('Waiting for selector', { selector, timeout });
        await this.state.page.waitForSelector(selector, { timeout });
        this.log('Selector found');
      } catch (error: any) {
        console.error('Wait for selector error:', error);
        throw new BrowserError('Selector not found within timeout', 'Check if the selector appears on the page');
      }
    }
  • Input schema definition for the waitForSelector tool, specifying selector (required) and optional timeout.
    const WAIT_FOR_SELECTOR_TOOL: Tool = {
      name: "waitForSelector",
      description: "Wait for a specific selector to appear on the page",
      inputSchema: {
        type: "object",
        properties: {
          selector: { type: "string" },
          timeout: { 
            type: "number",
            description: "Timeout in milliseconds (default: 30000)"
          }
        },
        required: ["selector"]
      }
    };
  • src/server.ts:541-541 (registration)
    Registration of the waitForSelector tool in the tools object passed to MCP server capabilities.
    waitForSelector: WAIT_FOR_SELECTOR_TOOL,
  • src/server.ts:860-871 (registration)
    Dispatch handler in the callTool request handler switch statement that invokes the playwrightController's waitForSelector method.
    case 'waitForSelector': {
      if (!args.selector) {
        return {
          content: [{ type: "text", text: "Selector is required" }],
          isError: true
        };
      }
      await playwrightController.waitForSelector(args.selector as string, args.timeout as number);
      return {
        content: [{ type: "text", text: "Selector found successfully" }]
      };
    }

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/jomon003/PlayMCP'

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