Skip to main content
Glama
JMRMEDEV

Enhanced Web Scraper MCP Server

by JMRMEDEV

wait_for_element

Wait for a specific element to appear on a webpage using CSS selectors, handling dynamic content loading and React applications with configurable timeout and browser support.

Instructions

Wait for an element to appear on the page (useful for dynamic React content)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
browserNoBrowser engine to usechromium
selectorYesCSS selector to wait for
timeoutNoMaximum time to wait in milliseconds
urlYesURL to monitor

Implementation Reference

  • The main handler function for 'wait_for_element' tool. Launches browser, navigates to URL, uses findElement helper to wait for selector, retrieves element properties, and returns success details including wait time, visibility, text, testID, and accessibility label.
      async waitForElement(args) {
        this.validateArgs(args, ['url', 'selector']);
        const { url, selector, timeout = TIMEOUTS.DEFAULT, browser: browserType = 'chromium' } = args;
        
        const { browser, context } = await this.getBrowser(browserType);
        const page = await context.newPage();
        
        try {
          await page.goto(url, { waitUntil: 'networkidle' });
          
          const startTime = Date.now();
          const { element, usedSelector } = await this.findElement(page, selector, timeout);
          
          const waitTime = Date.now() - startTime;
          const text = await element.textContent();
          const isVisible = await element.isVisible();
          const testId = await element.getAttribute('data-testid');
          const accessibilityLabel = await element.getAttribute('aria-label');
    
          return {
            content: [{
              type: 'text',
              text: `✅ Element found: ${usedSelector}
    Wait time: ${waitTime}ms
    Visible: ${isVisible}
    Text content: "${text?.trim()}"${testId ? `\nTestID: ${testId}` : ''}${accessibilityLabel ? `\nAccessibility Label: ${accessibilityLabel}` : ''}`
            }]
          };
        } finally {
          await context.close();
          await browser.close();
        }
  • server.js:447-475 (registration)
    Registration of the 'wait_for_element' tool in the list of tools returned by ListToolsRequestSchema, including name, description, and input schema.
    {
      name: 'wait_for_element',
      description: 'Wait for an element to appear on the page (useful for dynamic React content)',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'URL to monitor'
          },
          selector: {
            type: 'string',
            description: 'CSS selector to wait for'
          },
          timeout: {
            type: 'number',
            default: 10000,
            description: 'Maximum time to wait in milliseconds'
          },
          browser: {
            type: 'string',
            enum: ['chromium', 'firefox', 'webkit'],
            default: 'chromium',
            description: 'Browser engine to use'
          }
        },
        required: ['url', 'selector']
      }
    },
  • Input schema definition for the 'wait_for_element' tool, specifying required url and selector, optional timeout and browser.
    type: 'object',
    properties: {
      url: {
        type: 'string',
        description: 'URL to monitor'
      },
      selector: {
        type: 'string',
        description: 'CSS selector to wait for'
      },
      timeout: {
        type: 'number',
        default: 10000,
        description: 'Maximum time to wait in milliseconds'
      },
      browser: {
        type: 'string',
        enum: ['chromium', 'firefox', 'webkit'],
        default: 'chromium',
        description: 'Browser engine to use'
      }
    },
    required: ['url', 'selector']
  • Helper function used by waitForElement to locate the element using multiple selector strategies: exact CSS, data-testid, aria-label, accessibilityLabel. Tries each with proportional timeout and returns the element and used selector.
    async findElement(page, selector, timeout = TIMEOUTS.DEFAULT) {
      const selectors = [
        selector,
        `[data-testid="${selector}"]`,
        `[aria-label="${selector}"]`,
        `[accessibilityLabel="${selector}"]`
      ];
      
      for (const sel of selectors) {
        try {
          await page.waitForSelector(sel, { timeout: timeout / selectors.length });
          return { element: await page.$(sel), usedSelector: sel };
        } catch (e) {
          continue;
        }
      }
      throw new Error(`Element not found with any selector: ${selector}`);
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 mentions waiting for dynamic React content but doesn't describe what happens on success/failure, whether it polls continuously, what error conditions exist, or what permissions/browser state is required. The description is too minimal for a tool that interacts with browser automation.

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 extremely concise with just one sentence containing 11 words. Every word earns its place: 'Wait for an element to appear on the page' states the core purpose, and '(useful for dynamic React content)' adds valuable context. No wasted words or redundancy.

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?

For a browser automation tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns, what happens when the element doesn't appear, or how it interacts with the browser context. The React mention is helpful but insufficient for the tool's complexity.

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?

Schema description coverage is 100%, so the schema already documents all 4 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema. The baseline of 3 is appropriate since the schema does the heavy lifting, though the description doesn't compensate with additional context about parameter interactions.

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: 'Wait for an element to appear on the page' with the specific verb 'wait' and resource 'element'. It distinguishes from some siblings like 'scrape_page' or 'get_page_info' by focusing on waiting rather than retrieving information, though it doesn't explicitly differentiate from all siblings like 'wait_for_react_state'.

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

Usage Guidelines3/5

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

The description provides implied usage guidance with '(useful for dynamic React content)', suggesting it's for React-based pages. However, it doesn't explicitly state when to use this tool versus alternatives like 'wait_for_react_state' or 'inspect_element', nor does it provide clear exclusions or prerequisites for usage.

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/JMRMEDEV/amazon-q-web-scraper-mcp'

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