Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright Server Selectors

From Leeroopedia

Template:Implementation Page

Overview

Selectors is the server-side selector engine registry that manages built-in and custom selector engines, validates selector names, and parses selector strings into structured representations.

Description

The Selectors class maintains the registry of all available selector engines including built-in engines (css, xpath, text, role, etc.) and user-registered custom engines. It validates engine names, manages the test ID attribute name configuration, and provides the parseSelector method that converts selector strings into ParsedSelector objects.

Built-in engines include: css, xpath, text, id, role, data-testid, internal engines (has, has-text, chain, etc.), and framework-specific engines (_react, _vue).

Usage

One Selectors instance per browser context. Custom engines are registered via the public API.

Code Reference

Source Location

packages/playwright-core/src/server/selectors.ts (96 lines)

Class Signature

export class Selectors {
  readonly guid: string;
  constructor(engines: channels.SelectorEngine[], testIdAttributeName: string | undefined)
  register(engine: channels.SelectorEngine): void
  unregisterAll(): void
  parseSelector(selector: string | ParsedSelector, strict: boolean): SelectorInfo
}

Import

import { Selectors } from './server/selectors';

I/O Contract

Inputs

  • engines: channels.SelectorEngine[] -- custom engines to register at creation
  • testIdAttributeName: string -- the attribute name for test IDs (default: data-testid)

Outputs

  • Parsed selector structures with engine name, body, and world information
  • Validation errors for invalid selector names or unregistered engines

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment