grafana/k6 · error

waiting for selector

Error message

waiting for selector %q did not result in any nodes

What it means

Returned by Frame.waitForSelector when the internal waitFor call succeeded but produced a nil handle: the wait condition ended (typically timeout with state 'attached' semantics or state 'detached' transitions) without matching any node. Contrary to the message wording, it usually means the selector never matched within the wait's parameters rather than an internal failure.

Solutions

  1. Verify the selector actually matches elements in the frame
  2. Increase the wait timeout
  3. Check the state option: waiting for 'detached' or wrong state can yield no handle
  4. Ensure you are waiting on the correct frame (iframe vs main)
Defensive patterns

Strategy: retry

When it happens

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

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-09-20). Data as JSON: /api/errors/1296a238ba53b2f1. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/frame.go:507

// waitForSelector will wait for the given selector to reach a defined state in
// opts.
//
// It will auto retry on certain errors until the retryCount is below 0. The
// retry workaround is needed since the underlying DOM can change when the
// wait action is performed during a navigation.
func (f *Frame) waitForSelector(selector string, opts *FrameWaitForSelectorOptions) (*ElementHandle, error) {
	f.log.Debugf("Frame:waitForSelector", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)

	handle, err := f.waitFor(selector, opts, 20)
	if err != nil {
		return nil, err
	}
	if handle == nil {
		if opts.State == DOMElementStateHidden || opts.State == DOMElementStateDetached {
			return nil, nil //nolint:nilnil
		}
		return nil, fmt.Errorf("waiting for selector %q did not result in any nodes", selector)
	}

	// We always return ElementHandles in the main execution context (aka "DOM world")
	f.executionContextMu.RLock()
	defer f.executionContextMu.RUnlock()

	uec := f.executionContexts[utilityWorld]

	// An element should belong to the current main world execution context, and
	// not to the utility world context, otherwise, we should adopt it to the
	// current world's execution context. This is only valid when the handle
	// is from the current frame and not part of a nested frame.
	adopted := handle
	if uec != nil && uec == handle.execCtx {
		wec := f.executionContexts[mainWorld]
		if wec == nil {
			return nil, fmt.Errorf("waiting for selector %q: execution context %q not found", selector, mainWorld)
		}

View on GitHub (pinned to 3fcf5388d7)