Skip to main content
Glama

playwright_select

Select a specific option from a dropdown or select element on a webpage using a CSS selector and desired value, enabling precise interaction in browser automation tasks.

Instructions

Select an element on the page with Select tag

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for element to select
valueYesValue to select

Implementation Reference

  • The SelectTool.execute method implements the core logic of the playwright_select tool, waiting for the selector and calling page.selectOption with the provided value.
    /**
     * Tool for selecting options from dropdown menus
     */
    export class SelectTool extends BrowserToolBase {
      /**
       * Execute the select tool
       */
      async execute(args: any, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async (page) => {
          await page.waitForSelector(args.selector);
          await page.selectOption(args.selector, args.value);
          return createSuccessResponse(`Selected ${args.selector} with: ${args.value}`);
        });
      }
    }
  • The tool definition including name, description, and input schema (selector and value) for playwright_select.
      name: "playwright_select",
      description: "Select an element on the page with Select tag",
      inputSchema: {
        type: "object",
        properties: {
          selector: { type: "string", description: "CSS selector for element to select" },
          value: { type: "string", description: "Value to select" },
        },
        required: ["selector", "value"],
      },
    },
  • Switch case in handleToolCall that dispatches to the SelectTool handler for "playwright_select".
    case "playwright_select":
      return await selectTool.execute(args, context);
  • Initialization of the SelectTool instance used for handling playwright_select.
    if (!selectTool) selectTool = new SelectTool(server);
  • Code generation helper that produces Playwright test code for the select action.
        case 'playwright_select':
          return this.generateSelectStep(parameters);
        case 'playwright_custom_user_agent':
          return this.generateCustomUserAgentStep(parameters);
        default:
          console.warn(`Unsupported tool: ${toolName}`);
          return null;
      }
    }
    
    private generateNavigateStep(parameters: Record<string, unknown>): string {
      const { url, waitUntil } = parameters;
      const options = waitUntil ? `, { waitUntil: '${waitUntil}' }` : '';
      return `
      // Navigate to URL
      await page.goto('${url}'${options});`;
    }
    
    private generateFillStep(parameters: Record<string, unknown>): string {
      const { selector, value } = parameters;
      return `
      // Fill input field
      await page.fill('${selector}', '${value}');`;
    }
    
    private generateClickStep(parameters: Record<string, unknown>): string {
      const { selector } = parameters;
      return `
      // Click element
      await page.click('${selector}');`;
    }
    
    private generateScreenshotStep(parameters: Record<string, unknown>): string {
      const { name, fullPage = false, path } = parameters;
      const options = [];
      if (fullPage) options.push('fullPage: true');
      if (path) options.push(`path: '${path}'`);
      
      const optionsStr = options.length > 0 ? `, { ${options.join(', ')} }` : '';
      return `
      // Take screenshot
      await page.screenshot({ path: '${name}.png'${optionsStr} });`;
    }
    
    private generateExpectResponseStep(parameters: Record<string, unknown>): string {
      const { url, id } = parameters;
      return `
      // Wait for response
      const ${id}Response = page.waitForResponse('${url}');`;
    }
    
    private generateAssertResponseStep(parameters: Record<string, unknown>): string {
      const { id, value } = parameters;
      const assertion = value 
        ? `\n    const responseText = await ${id}Response.text();\n    expect(responseText).toContain('${value}');`
        : `\n    expect(${id}Response.ok()).toBeTruthy();`;
      return `
      // Assert response${assertion}`;
    }
    
    private generateHoverStep(parameters: Record<string, unknown>): string {
      const { selector } = parameters;
      return `
      // Hover over element
      await page.hover('${selector}');`;
    }
    
    private generateSelectStep(parameters: Record<string, unknown>): string {
      const { selector, value } = parameters;
      return `
      // Select option
      await page.selectOption('${selector}', '${value}');`;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It implies a mutation action ('Select') but doesn't disclose behavioral traits such as error handling, whether it waits for the element, or what happens if the selector is invalid. This leaves significant gaps in understanding how the tool behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, direct sentence with no wasted words. It front-loads the key action and target, making it efficient and easy to parse, which is ideal for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a mutation tool. It lacks details on behavior, error cases, and return values, which are crucial for an AI agent to use the tool effectively in a web automation context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for both parameters (selector and value). The description adds minimal value beyond the schema, only implying that the element must be a 'Select tag', which provides some context but doesn't elaborate on parameter usage or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Select') and target ('element on the page with Select tag'), making the purpose understandable. It distinguishes from siblings like playwright_click or playwright_fill by specifying it's for Select elements, though it doesn't explicitly contrast with all similar tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites like requiring a page to be loaded, nor does it differentiate from other playwright tools that might interact with elements, leaving the agent to infer usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/executeautomation/mcp-playwright'

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