{"record":{"id":"88cb74c2eec14d88","repo":"grafana/k6","slug":"checking-is-q-hidden-w","errorCode":null,"errorMessage":"checking is %q hidden: %w","messagePattern":"checking is %q hidden: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":1549,"sourceCode":"\thidden, err := f.isHidden(selector, opts)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\n\treturn hidden, nil\n}\n\nfunc (f *Frame) isHidden(selector string, opts *FrameIsHiddenOptions) (bool, error) {\n\tisHidden := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\tv, err := handle.isHidden(apiCtx) // Zero timeout when checking state\n\t\tif errors.Is(err, ErrTimedOut) {  // We don't care about timeout errors here!\n\t\t\treturn v, nil\n\t\t}\n\t\treturn v, err\n\t}\n\tv, err := f.runActionOnSelector(f.ctx, selector, opts.Strict, isHidden, func() bool { return true })\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"checking is %q hidden: %w\", selector, err)\n\t}\n\n\treturn v, nil\n}\n\n// IsVisible returns true if the first element that matches the selector\n// is visible. Otherwise, returns false.\nfunc (f *Frame) IsVisible(selector string, opts *FrameIsVisibleOptions) (bool, error) {\n\tf.log.Debugf(\"Frame:IsVisible\", \"fid:%s furl:%q sel:%q\", f.ID(), f.URL(), selector)\n\n\tvisible, err := f.isVisible(selector, opts)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\n\treturn visible, nil\n}\n","sourceCodeStart":1531,"sourceCodeEnd":1567,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L1531-L1567","documentation":"Thrown by k6 browser's frame.isHidden(selector) when the internal visibility check cannot run at all. The code resolves the selector via Query, runs handle.isHidden (deliberately swallowing ErrTimedOut), and only errors when selector resolution or the underlying CDP call fails. A missing element is NOT an error here: it returns the default (true for isHidden).","triggerScenarios":"Calling page.isHidden(sel)/frame.isHidden(sel) when the wrapped Query fails: malformed CSS/XPath selector (parse error), the frame's execution context being destroyed by a concurrent navigation, or the page/target already being closed.","commonSituations":"k6 browser scripts that call isHidden right after page.goto() while navigation is still settling, scripts that keep operating on a page after browser.close()/test teardown, or a typo'd selector string that the CSS parser rejects.","solutions":["Verify the selector is valid CSS (or a k6-supported selector engine) by testing it in DevTools","Wait for navigation/load to settle before checking: page.waitForLoadState('load') or page.waitForNavigation","Ensure the page is not closed or navigating when isHidden is called; check page.isClosed()","Wrap the call in try-catch and treat an error as 'unknown' rather than assuming hidden"],"exampleFix":"// before\nconst hidden = page.isHidden('#submit');\n\n// after\nlet hidden = true;\ntry {\n  hidden = page.isHidden('#submit');\n} catch (e) {\n  console.log(`visibility check failed, assuming hidden: ${e}`);\n}","handlingStrategy":"try-catch","validationCode":"if (page.isClosed()) { throw new Error('page closed; skip isHidden check'); }\npage.waitForLoadState('domcontentloaded');","typeGuard":null,"tryCatchPattern":"let hidden = true; // fail-safe default\ntry {\n  hidden = page.isHidden(sel);\n} catch (e) {\n  console.log(`isHidden('${sel}') unavailable: ${e}`);\n}","preventionTips":["Validate selector strings before the run (unit-test or lint them)","Never call frame APIs on a page you already closed","Let goto()/navigation settle with waitForLoadState before probing visibility"],"tags":["k6","browser","frame","selector","visibility"],"backgroundTag":"selector-resolution-failed","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"}