{"record":{"id":"33998c7cf0b3b7b4","repo":"grafana/k6","slug":"querying-selector-q-w","errorCode":null,"errorMessage":"querying selector %q: %w","messagePattern":"querying selector %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1226,"sourceCode":"\t\t\treturn nil, err\n\t\t}\n\n\t\treturn frame.Query(afterFrameSelector, strict)\n\t}\n\n\t// No frame navigation - proceed with normal Query logic\n\tquerySelector := `\n\t\t(node, injected, selector, strict) => {\n\t\t\treturn injected.querySelector(selector, strict, node || document);\n\t\t}\n\t`\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: false,\n\t}\n\tresult, err := h.evalWithScript(h.ctx, opts, querySelector, parsedSelector, strict)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"querying selector %q: %w\", selector, err)\n\t}\n\tif result == nil {\n\t\treturn nil, nil //nolint:nilnil\n\t}\n\thandle, ok := result.(JSHandleAPI)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"querying selector %q, wrong type %T\", selector, result)\n\t}\n\telement := handle.AsElement()\n\tif element == nil {\n\t\tdefer func() {\n\t\t\tif err := handle.Dispose(); err != nil {\n\t\t\t\terr = fmt.Errorf(\"disposing element handle: %w\", err)\n\t\t\t\trerr = errors.Join(err, rerr)\n\t\t\t}\n\t\t}()\n\t\treturn nil, fmt.Errorf(\"querying selector %q\", selector)\n\t}","sourceCodeStart":1208,"sourceCodeEnd":1244,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L1208-L1244","documentation":"Returned by ElementHandle.Query when evaluating the injected querySelector script against the element's subtree fails in the page's execution context. The wrapped error is the evaluation failure: navigation destroyed the context, a JS exception in the injected script, or a CDP session error. The selector itself parsed fine.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/element_handle.go:1226 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the query after navigation or DOM changes settle","Ensure the frame's execution context is alive (page not navigating)","Check the wrapped error for a JS exception detail and adjust usage accordingly"],"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"}