waitForSelector
Pause execution until a specified element, identified by a CSS selector or XPath, appears on the webpage, with configurable timeout and state conditions for precise control.
Instructions
等待指定选择器的元素出现
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pageId | Yes | 页面ID | |
| selector | Yes | CSS选择器或xp引用值 | |
| state | No | 等待的状态(默认visible) | |
| timeout | No | 超时时间(毫秒,默认30000) |
Implementation Reference
- src/server/playwright-server.ts:704-711 (handler)Core handler function that implements waitForSelector by calling Playwright's page.waitForSelector on the specified page.async waitForSelector(pageId: string, selector: string, options?: any) { const pageInfo = this.pages.get(pageId); if (!pageInfo) { throw new Error(`Page ${pageId} not found`); } await pageInfo.page.waitForSelector(selector, options); }
- src/server/playwright-server.ts:338-347 (registration)HTTP endpoint registration that exposes the waitForSelector functionality via POST /api/pages/:pageId/wait-selector.this.app.post('/api/pages/:pageId/wait-selector', async (req: Request, res: Response) => { try { const { pageId } = req.params; const { selector, options } = req.body; await this.waitForSelector(pageId, selector, options); res.json({ success: true }); } catch (error: any) { res.status(500).json({ error: error.message }); } });