Skip to main content
Glama

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
NameRequiredDescriptionDefault
selectorYesCSS selector for the element
valuesYesOption values to select
timeoutNoTimeout in milliseconds
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • 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))); } }
  • 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, });
  • 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))); } } );

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/andytango/puppeteer-mcp'

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