select
Select options from dropdown elements on web pages using CSS selectors and option values for automated browser interaction.
Instructions
Select option(s) from a dropdown/select element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for the element | |
| values | Yes | Option values to select | |
| timeout | No | Timeout in milliseconds | |
| tabId | No | Tab ID to operate on (uses active tab if not specified) |
Implementation Reference
- src/tools/interaction.ts:106-125 (handler)Handler function that executes the select tool: waits for select element, calls page.select() with values, returns selected options.const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; const timeoutMs = timeout ?? getDefaultTimeout(); try { await page.waitForSelector(selector, { timeout: timeoutMs }); const selected = await page.select(selector, ...values); return handleResult(ok({ selected, selector })); } catch (error) { if (error instanceof Error && error.message.includes('waiting for selector')) { return handleResult(err(selectorNotFound(selector))); } return handleResult(err(normalizeError(error))); } }
- src/schemas.ts:68-73 (schema)Zod input schema for the 'select' tool defining parameters: selector (CSS selector), values (array of option values), optional timeout and tabId.export const selectSchema = z.object({ selector: selectorSchema, values: z.array(z.string()).min(1).describe('Option values to select'), timeout: timeoutSchema, tabId: tabIdSchema, });
- src/tools/interaction.ts:102-126 (registration)MCP tool registration for 'select' including description, input schema, and inline handler function.'select', 'Select option(s) from a dropdown/select element', selectSchema.shape, async ({ selector, values, timeout, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; const timeoutMs = timeout ?? getDefaultTimeout(); try { await page.waitForSelector(selector, { timeout: timeoutMs }); const selected = await page.select(selector, ...values); return handleResult(ok({ selected, selector })); } catch (error) { if (error instanceof Error && error.message.includes('waiting for selector')) { return handleResult(err(selectorNotFound(selector))); } return handleResult(err(normalizeError(error))); } } );