grafana/k6 · error
waiting for selector
Error message
waiting for selector %q: execution context %q not found
What it means
Returned by Frame.waitForSelector when the handle found by the wait belongs to the utility world and the main-world execution context needed for adoption is not present in the frame's context map. A race: the frame navigated between finding the element and adopting it, leaving no main-world context.
Solutions
- Retry the wait after navigation completes
- Wait for load state before waitForSelector on freshly navigated frames
- Avoid triggering navigations concurrently with the wait
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/frame.go:516 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/3df071fdbc719321.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/frame.go:524
}
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)
}
if adopted, err = wec.adoptElementHandle(handle); err != nil {
return nil, fmt.Errorf("waiting for selector %q: adopting element handle: %w", selector, err)
}
if err = handle.Dispose(); err != nil {
f.log.Warnf(
"Frame:waitForSelector",
"fid:%s furl:%q sel:%q disposing element handle: %v",
f.ID(), f.URL(), selector, err,
)
}
}
return adopted, nil
}
View on GitHub (pinned to 3fcf5388d7)