click_element
Click a web page element using a CSS selector. Specify the selector and optional timeout to ensure the element is interacted with correctly.
Instructions
Click on an element by CSS selector
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for the element to click | |
| timeout | No | Timeout in milliseconds |
Implementation Reference
- src/index.ts:28-31 (schema)Zod schema for click_element input validation: requires 'selector' (string) and optional 'timeout' (number, default 5000).
const ClickElementSchema = z.object({ selector: z.string(), timeout: z.number().default(5000) }); - src/index.ts:178-195 (registration)Registration of the 'click_element' tool in the ListToolsRequestSchema handler, including description and input schema definition.
name: 'click_element', description: 'Click on an element by CSS selector', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector for the element to click' }, timeout: { type: 'number', default: 5000, description: 'Timeout in milliseconds' } }, required: ['selector'] } }, - src/index.ts:483-499 (handler)Handler for 'click_element' tool: validates input with ClickElementSchema, checks browser availability, uses Playwright's page.click() with the provided selector and timeout, and returns a success message.
case 'click_element': { if (!currentPage) { throw new Error('No browser page available. Launch a browser first.'); } const params = ClickElementSchema.parse(args); await currentPage.click(params.selector, { timeout: params.timeout }); return { content: [ { type: 'text', text: `Clicked element: ${params.selector}` } ] }; }