{"record":{"id":"9cc036648f47fb1b","repo":"grafana/k6","slug":"checking-element-is-checked-w","errorCode":null,"errorMessage":"checking element is checked: %w","messagePattern":"checking element is checked: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1058,"sourceCode":"\tv, err := call(h.ctx, inputValueAction, opts.Timeout)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"getting element's input value: %w\", err)\n\t}\n\n\ts, ok := v.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type %T (expecting string)\", v)\n\t}\n\n\treturn s, nil\n}\n\n// IsChecked checks if a checkbox or radio is checked.\nfunc (h *ElementHandle) IsChecked() (bool, error) {\n\tok, err := h.isChecked(h.ctx, 0)\n\t// We don't care about timeout errors here!\n\tif err != nil && !errors.Is(err, ErrTimedOut) {\n\t\treturn false, fmt.Errorf(\"checking element is checked: %w\", err)\n\t}\n\n\treturn ok, nil\n}\n\n// IsDisabled checks if the element is disabled.\nfunc (h *ElementHandle) IsDisabled() (bool, error) {\n\tok, err := h.isDisabled(h.ctx, 0)\n\t// We don't care anout timeout errors here!\n\tif err != nil && !errors.Is(err, ErrTimedOut) {\n\t\treturn false, fmt.Errorf(\"checking element is disabled: %w\", err)\n\t}\n\n\treturn ok, nil\n}\n\n// IsEditable checks if the element is editable.\nfunc (h *ElementHandle) IsEditable() (bool, error) {","sourceCodeStart":1040,"sourceCodeEnd":1076,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1040-L1076","documentation":"Returned by ElementHandle.isChecked() when the underlying state probe fails with a non-timeout error. The method calls waitForElementState(['checked']) with a 0 timeout and deliberately ignores ErrTimedOut (a timeout just means 'not checked yet'), so this error only surfaces for real failures: stale handle, destroyed execution context, CDP transport error, or closed browser/page.","triggerScenarios":"Calling isChecked() on a handle whose node was detached by a re-render; calling it after the page navigated (context destroyed); calling it after page.close(); CDP session dropped because the browser crashed.","commonSituations":"Keeping handles from page.$() across iterations of a loop that re-renders the list; checking state after a click navigates away; browser shutdown races at scenario end.","solutions":["Re-query the handle immediately before isChecked()","Wait for the element: page.waitForSelector(sel, { state: 'attached' })","Ensure the page is still open before probing state","Wrap in try/catch and treat a hard failure separately from a false result"],"exampleFix":"// before\nconst checked = await h.isChecked(); // h captured earlier\n// after\nconst el = await page.$('#agree'); // fresh handle\nconst checked = await el.isChecked();","handlingStrategy":"try-catch","validationCode":"const el = await page.$('#agree');\nif (el && (await el.isVisible())) {\n  const checked = await el.isChecked();\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await handle.isChecked();\n} catch (e) {\n  if (String(e).includes('checking element is checked')) {\n    const fresh = await page.$(sel);\n    return fresh ? fresh.isChecked() : false;\n  }\n  throw e;\n}","preventionTips":["Remember timeouts are ignored by design; an error means the handle or page is gone","Re-query handles immediately before state probes","Do not probe state after page.close() or during navigation"],"tags":["browser","element-handle","is-checked","detached-handle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}