browser_select_dropdown_by_value
Selects a specific option from a dropdown menu in a web browser using its value attribute. This tool helps automate form filling and UI testing by targeting dropdown elements with precision.
Instructions
Select dropdown by value
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| value | Yes | Value of the option to select | |
| timeout | No | Maximum time to wait for element in milliseconds |
Implementation Reference
- src/services/actionService.ts:53-58 (handler)Core handler function that locates the dropdown element using LocatorFactory, waits for it to be present, instantiates Selenium's Select class, and selects the option by its value attribute.async selectDropdownByValue(params: LocatorParams & { value: string }): Promise<void> { const locator = LocatorFactory.createLocator(params.by, params.value); const selectElement = await this.driver.wait(until.elementLocated(locator), params.timeout || 15000); const select = new Select(selectElement); await select.selectByValue(params.value); }
- src/tools/actionTools.ts:170-200 (registration)Registers the MCP tool 'browser_select_dropdown_by_value' using McpServer.tool(), defines input schema extending locatorSchema (with value overridden for option value), and provides a thin async handler that instantiates ActionService and delegates execution.server.tool( 'browser_select_dropdown_by_value', 'Select dropdown by value', { ...locatorSchema, value: z.string().describe('Value of the option to select'), }, async ({ by, value, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.selectDropdownByValue({ by, value, timeout }); return { content: [ { type: 'text', text: `Selected dropdown option by value: ${value}`, }, ], }; } catch (e) { return { content: [ { type: 'text', text: `Error selecting dropdown option by value: ${(e as Error).message}`, }, ], }; } }
- src/types/index.ts:29-35 (schema)Zod schema defining the base locator parameters (by, value, optional timeout), which is spread into 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'), };