browser_select_checkbox
Select checkboxes on web pages using various locator strategies to automate form interactions and UI testing.
Instructions
Select a checkbox
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| timeout | No | Maximum time to wait for element in milliseconds | |
| value | Yes | Value for the locator strategy |
Implementation Reference
- src/tools/actionTools.ts:378-396 (handler)MCP tool registration with inline handler function that executes the tool logic by calling ActionService.selectCheckbox on the located checkbox element.server.tool('browser_select_checkbox', 'Select a checkbox', { ...locatorSchema }, async ({ by, value }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.selectCheckbox({ by, value }); return { content: [{ type: 'text', text: `Selected checkbox` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error selecting checkbox: ${(e as Error).message}`, }, ], }; } });
- src/types/index.ts:29-35 (schema)Zod schema definition for locator parameters (by, value, optional timeout) used in the tool's input schema.export const locatorSchema = { by: z .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink']) .describe('Locator strategy to find element'), value: z.string().describe('Value for the locator strategy'), timeout: z.number().optional().describe('Maximum time to wait for element in milliseconds'), };
- Core implementation of checkbox selection: waits for the element using the locator, checks if not already selected, and clicks it if necessary.async selectCheckbox(params: LocatorParams): Promise<void> { const locator = LocatorFactory.createLocator(params.by, params.value); const checkbox = await this.driver.wait(until.elementLocated(locator), params.timeout || 15000); if (!(await checkbox.isSelected())) { await checkbox.click(); } }
- src/tools/index.ts:11-11 (registration)Higher-level registration call to registerActionTools, which includes the browser_select_checkbox tool, as part of registering all tools.registerActionTools(server, stateManager);