microsoft/playwright · error · Error

Malformed test id selector: ${selector}

Error message

Malformed test id selector: ${selector}

What it means

Error "Malformed test id selector: ${selector}" thrown in microsoft/playwright.

Source

Thrown at packages/injected/src/injectedScript.ts:518

  private _createNamedAttributeEngine(): SelectorEngine {
    const queryAll = (root: SelectorRoot, selector: string): Element[] => {
      const parsed = parseAttributeSelector(selector, true);
      if (parsed.name || parsed.attributes.length !== 1)
        throw new Error('Malformed attribute selector: ' + selector);
      const { name } = parsed.attributes[0];
      const matcher = createAttributeMatcher(parsed.attributes[0]);
      const elements = this._evaluator._queryCSS({ scope: root as Document | Element, pierceShadow: true }, `[${name}]`);
      return elements.filter(e => matcher(e.getAttribute(name)!));
    };
    return { queryAll };
  }

  private _createTestIdEngine(): SelectorEngine {
    const queryAll = (root: SelectorRoot, selector: string): Element[] => {
      const parsed = parseAttributeSelector(selector, true);
      if (parsed.name || parsed.attributes.length !== 1)
        throw new Error('Malformed test id selector: ' + selector);
      const names = splitTestIdAttributeNames(parsed.attributes[0].name);
      const matcher = createAttributeMatcher(parsed.attributes[0]);
      const cssQuery = names.map(n => `[${n}]`).join(',');
      const elements = this._evaluator._queryCSS({ scope: root as Document | Element, pierceShadow: true }, cssQuery);
      return elements.filter(e => names.some(n => {
        const actual = e.getAttribute(n);
        return actual !== null && matcher(actual);
      }));
    };
    return { queryAll };
  }

  private _createDescribeEngine(): SelectorEngine {
    const queryAll = (root: SelectorRoot): Element[] => {
      if (root.nodeType !== 1 /* Node.ELEMENT_NODE */)
        return [];
      return [root as Element];
    };

View on GitHub (pinned to c8fc3bf8d3)

When it happens

Trigger: Thrown at packages/injected/src/injectedScript.ts:518 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/09f77c35f2a69a0c. Report an issue: GitHub.