grafana/k6 · error

parsing selector

Error message

parsing selector %q: %w

What it means

Returned by ElementHandle.Query when NewSelector rejects the selector string during parsing. This is a user-input validation error: the selector is syntactically invalid for k6's selector engine (e.g. malformed combination of engine=selector parts, unclosed quotes or parens), before any DOM lookup happens.

Solutions

  1. Fix the selector syntax; use valid selector engine prefixes like 'css=', 'xpath=', 'text='
  2. Quote text selectors containing special characters
  3. Test the selector in browser devtools or with a simpler css selector first
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/element_handle.go:1192 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18). Data as JSON: /api/errors/ad9d5dd3d4faa79f. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/element_handle.go:1192

	}
	pressAction := h.newAction(
		[]string{}, press, false, withRetry, opts.NoWaitAfter, opts.Timeout,
	)
	if _, err := call(h.ctx, pressAction, opts.Timeout); err != nil {
		return fmt.Errorf("pressing %q on element: %w", key, err)
	}

	applySlowMo(h.ctx)

	return nil
}

// Query runs "element.querySelector" within the page. If no element matches the selector,
// the return value resolves to "null".
func (h *ElementHandle) Query(selector string, strict bool) (_ *ElementHandle, rerr error) {
	parsedSelector, err := NewSelector(selector)
	if err != nil {
		return nil, fmt.Errorf("parsing selector %q: %w", selector, err)
	}

	// Check for frame navigation in the selector
	frameNavIndex := h.findFrameNavigationIndex(parsedSelector)
	if frameNavIndex != -1 {
		// Strict is true because we assume the user is interested in the element
		// in the frame and not the frame it is in.
		opts := &FrameWaitForSelectorOptions{
			State:   DOMElementStateAttached,
			Timeout: h.frame.defaultTimeout(),
			Strict:  true,
		}

		frame, afterFrameSelector, err := h.stepIntoFrame(h.ctx, parsedSelector, frameNavIndex, opts)
		if err != nil {
			return nil, err
		}

View on GitHub (pinned to 3fcf5388d7)