waitForText
Monitor and pause automation until specific text appears on a webpage using PlayMCP Browser Automation Server. Set a timeout to control waiting duration.
Instructions
Wait for specific text to appear on the page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | ||
| timeout | No | Timeout in milliseconds (default: 30000) |
Implementation Reference
- src/controllers/playwright.ts:680-692 (handler)Core handler function in PlaywrightController that implements the waitForText logic using page.waitForSelector with text selector.async waitForText(text: string, timeout: number = 30000): Promise<void> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } this.log('Waiting for text', { text, timeout }); await this.state.page.waitForSelector(`text=${text}`, { timeout }); this.log('Text found'); } catch (error: any) { console.error('Wait for text error:', error); throw new BrowserError('Text not found within timeout', 'Check if the text appears on the page'); } }
- src/server.ts:327-341 (schema)Tool schema definition including input parameters: text (required string), timeout (optional number).const WAIT_FOR_TEXT_TOOL: Tool = { name: "waitForText", description: "Wait for specific text to appear on the page", inputSchema: { type: "object", properties: { text: { type: "string" }, timeout: { type: "number", description: "Timeout in milliseconds (default: 30000)" } }, required: ["text"] } };
- src/server.ts:514-553 (registration)Registration of the waitForText tool in the tools object provided to MCP server capabilities.const tools = { openBrowser: OPEN_BROWSER_TOOL, navigate: NAVIGATE_TOOL, type: TYPE_TOOL, click: CLICK_TOOL, moveMouse: MOVE_MOUSE_TOOL, scroll: SCROLL_TOOL, screenshot: SCREENSHOT_TOOL, getPageSource: GET_PAGE_SOURCE_TOOL, getPageText: GET_PAGE_TEXT_TOOL, getPageTitle: GET_PAGE_TITLE_TOOL, getPageUrl: GET_PAGE_URL_TOOL, getScripts: GET_SCRIPTS_TOOL, getStylesheets: GET_STYLESHEETS_TOOL, getMetaTags: GET_META_TAGS_TOOL, getLinks: GET_LINKS_TOOL, getImages: GET_IMAGES_TOOL, getForms: GET_FORMS_TOOL, getElementContent: GET_ELEMENT_CONTENT_TOOL, getElementHierarchy: GET_ELEMENT_HIERARCHY_TOOL, executeJavaScript: EXECUTE_JAVASCRIPT_TOOL, goForward: GO_FORWARD_TOOL, hover: HOVER_TOOL, dragAndDrop: DRAG_AND_DROP_TOOL, selectOption: SELECT_OPTION_TOOL, pressKey: PRESS_KEY_TOOL, waitForText: WAIT_FOR_TEXT_TOOL, waitForSelector: WAIT_FOR_SELECTOR_TOOL, resize: RESIZE_TOOL, handleDialog: HANDLE_DIALOG_TOOL, getConsoleMessages: GET_CONSOLE_MESSAGES_TOOL, getNetworkRequests: GET_NETWORK_REQUESTS_TOOL, uploadFiles: UPLOAD_FILES_TOOL, evaluateWithReturn: EVALUATE_WITH_RETURN_TOOL, takeScreenshot: TAKE_SCREENSHOT_TOOL, mouseMove: MOUSE_MOVE_TOOL, mouseClick: MOUSE_CLICK_TOOL, mouseDrag: MOUSE_DRAG_TOOL, closeBrowser: CLOSE_BROWSER_TOOL };
- src/server.ts:847-858 (registration)Dispatch handler in callTool request handler that validates input and calls the Playwright controller's waitForText method.case 'waitForText': { if (!args.text) { return { content: [{ type: "text", text: "Text is required" }], isError: true }; } await playwrightController.waitForText(args.text as string, args.timeout as number); return { content: [{ type: "text", text: "Text found successfully" }] }; }