{"record":{"id":"97ef4a90c0bbdd42","repo":"grafana/k6","slug":"waiting-for-selector-q-adopting-element-handle","errorCode":null,"errorMessage":"waiting for selector %q: adopting element handle: %w","messagePattern":"waiting for selector %q: adopting element handle: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":528,"sourceCode":"\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\nfunc (f *Frame) waitFor(\n\tselector string, opts *FrameWaitForSelectorOptions, retryCount int,\n) (_ *ElementHandle, rerr error) {\n\tf.log.Debugf(\"Frame:waitFor\", \"fid:%s furl:%q sel:%q\", f.ID(), f.URL(), selector)","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L510-L546","documentation":"Returned by Frame.waitForSelector when the located element handle (from the utility world) must be adopted into the frame's main-world execution context and that adoption call fails. The wrapped error is the CDP adoption failure; typically the element or context became invalid mid-flight due to DOM changes or navigation.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame.go:520 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry waitForSelector after the DOM/navigation settles","Increase timeout so adoption retries can succeed","Check wrapped error for node-missing or context-destroyed causes"],"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"}