Skip to main content
Glama

wait_for_element

Wait for a web element to appear using a CSS selector, then extract its content from dynamic pages during web scraping.

Instructions

Wait for an element to appear and extract its content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to scrape
selectorYesCSS selector to wait for
timeoutNoTimeout in milliseconds

Implementation Reference

  • Core handler function that launches a Puppeteer browser, navigates to the URL, waits for the specified selector, extracts and returns the element's text content.
    async waitForElement(config: ScrapingConfig, selector: string): Promise<string> { const browser = await this.getBrowser(); const page = await browser.newPage(); try { await page.goto(config.url, { waitUntil: 'networkidle', timeout: config.timeout || 30000, }); await page.waitForSelector(selector, { timeout: config.waitForTimeout || 10000, }); const text = await page.textContent(selector); return text || ''; } finally { await page.close(); } }
  • Tool registration object defining the name, description, and input schema for the 'wait_for_element' tool.
    { name: 'wait_for_element', description: 'Wait for an element to appear and extract its content', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'URL to scrape', }, selector: { type: 'string', description: 'CSS selector to wait for', }, timeout: { type: 'number', description: 'Timeout in milliseconds', default: 10000, }, }, required: ['url', 'selector'], }, },
  • Dispatcher handler case in handleWebScrapingTool that extracts parameters and delegates to DynamicScraper.waitForElement.
    case 'wait_for_element': { const selector = params.selector as string; const content = await dynamicScraper.waitForElement(config, selector); return { selector, content }; }
  • Input schema defining the expected parameters: url, selector, and optional timeout for the tool.
    inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'URL to scrape', }, selector: { type: 'string', description: 'CSS selector to wait for', }, timeout: { type: 'number', description: 'Timeout in milliseconds', default: 10000, }, }, required: ['url', 'selector'], },

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/code-alchemist01/development-tools-mcp-Server'

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