Skip to main content
Glama

browser_select_option

Select values in dropdown menus during browser automation. Use this Playwright MCP tool to interact with web page dropdowns by specifying element references and desired values.

Instructions

Select an option in a dropdown

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
elementYesHuman-readable element description used to obtain permission to interact with the element
refYesExact target element reference from the page snapshot
valuesYesArray of values to select in the dropdown. This can be a single value or multiple values.

Implementation Reference

  • Implements the core logic for the browser_select_option tool: parses input using selectOptionSchema, locates the target element via snapshot reference, generates explanatory Playwright code snippet, performs the selectOption action on the locator, and returns the code.
    handle: async (context, params) => {
      const validatedParams = selectOptionSchema.parse(params);
      return await context.currentTab().runAndWaitWithSnapshot(async snapshot => {
        const locator = snapshot.refLocator(validatedParams.ref);
        const code = [
          `// Select options [${validatedParams.values.join(', ')}] in ${validatedParams.element}`,
          `await page.${await generateLocator(locator)}.selectOption(${javascript.formatObject(validatedParams.values)});`
        ];
        await locator.selectOption(validatedParams.values);
        return { code };
      });
    },
  • Defines the tool schema including name 'browser_select_option', description, and input schema derived from selectOptionSchema.
    schema: {
      name: 'browser_select_option',
      description: 'Select an option in a dropdown',
      inputSchema: zodToJsonSchema(selectOptionSchema),
    },
  • Zod type definition for the input schema of browser_select_option, extending shared elementSchema with 'values' array parameter.
    const selectOptionSchema = elementSchema.extend({
      values: z.array(z.string()).describe('Array of values to select in the dropdown. This can be a single value or multiple values.'),
    });
  • Registers the browser_select_option tool by including the selectOption object in the exported array of tools from this module.
    selectOption,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/markbustamante77/mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server