{"record":{"id":"f8a5903bbe4dda83","repo":"grafana/k6","slug":"querying-selector-q","errorCode":null,"errorMessage":"querying selector %q","messagePattern":"querying selector %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1243,"sourceCode":"\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}\n\n\treturn element, nil\n}\n\n// QueryAll queries element subtree for matching elements.\n// If no element matches the selector, the return value resolves to \"null\".\nfunc (h *ElementHandle) QueryAll(selector string) ([]*ElementHandle, error) {\n\thandles, err := h.queryAll(selector, h.evalWithScript)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"querying all selector %q: %w\", selector, err)\n\t}\n\n\treturn handles, nil\n}\n\nfunc (h *ElementHandle) queryAll(selector string, eval evalFunc) (_ []*ElementHandle, rerr error) {\n\tparsedSelector, err := NewSelector(selector)","sourceCodeStart":1225,"sourceCodeEnd":1261,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L1225-L1261","documentation":"Returned by ElementHandle.Query when the querySelector evaluation succeeded and returned a JSHandle, but handle.AsElement() is nil, meaning the selector matched a non-element node (or null coerced to a handle). The code disposes the useless handle and reports that the selector did not yield an element in the element's subtree.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/element_handle.go:1243 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a selector that matches element nodes only","Switch to QueryAll and inspect matches if unsure what the selector returns","If null is expected when nothing matches, check the k6 version: newer builds return nil instead of erroring"],"exampleFix":null,"handlingStrategy":"validation","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"}