{"record":{"id":"3df071fdbc719321","repo":"grafana/k6","slug":"waiting-for-selector-q-execution-context-q-not","errorCode":null,"errorMessage":"waiting for selector %q: execution context %q not found","messagePattern":"waiting for selector %q: execution context %q not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":524,"sourceCode":"\t\t}\n\t\treturn nil, fmt.Errorf(\"waiting for selector %q did not result in any nodes\", selector)\n\t}\n\n\t// We always return ElementHandles in the main execution context (aka \"DOM world\")\n\tf.executionContextMu.RLock()\n\tdefer f.executionContextMu.RUnlock()\n\n\tuec := f.executionContexts[utilityWorld]\n\n\t// An element should belong to the current main world execution context, and\n\t// not to the utility world context, otherwise, we should adopt it to the\n\t// current world's execution context. This is only valid when the handle\n\t// is from the current frame and not part of a nested frame.\n\tadopted := handle\n\tif uec != nil && uec == handle.execCtx {\n\t\twec := f.executionContexts[mainWorld]\n\t\tif wec == nil {\n\t\t\treturn nil, fmt.Errorf(\"waiting for selector %q: execution context %q not found\", selector, mainWorld)\n\t\t}\n\n\t\tif adopted, err = wec.adoptElementHandle(handle); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"waiting for selector %q: adopting element handle: %w\", selector, err)\n\t\t}\n\n\t\tif err = handle.Dispose(); err != nil {\n\t\t\tf.log.Warnf(\n\t\t\t\t\"Frame:waitForSelector\",\n\t\t\t\t\"fid:%s furl:%q sel:%q disposing element handle: %v\",\n\t\t\t\tf.ID(), f.URL(), selector, err,\n\t\t\t)\n\t\t}\n\t}\n\n\treturn adopted, nil\n}\n","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L506-L542","documentation":"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.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame.go:516 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the wait after navigation completes","Wait for load state before waitForSelector on freshly navigated frames","Avoid triggering navigations concurrently with the wait"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}