{"record":{"id":"3686667c3d6a2fca","repo":"grafana/k6","slug":"checking-element-is-enabled-w","errorCode":null,"errorMessage":"checking element is enabled: %w","messagePattern":"checking element is enabled: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1091,"sourceCode":"}\n\n// IsEditable checks if the element is editable.\nfunc (h *ElementHandle) IsEditable() (bool, error) {\n\tok, err := h.isEditable(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 editable: %w\", err)\n\t}\n\n\treturn ok, nil\n}\n\n// IsEnabled checks if the element is enabled.\nfunc (h *ElementHandle) IsEnabled() (bool, error) {\n\tok, err := h.isEnabled(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 enabled: %w\", err)\n\t}\n\n\treturn ok, nil\n}\n\n// IsHidden checks if the element is hidden.\nfunc (h *ElementHandle) IsHidden() (bool, error) {\n\tok, err := h.isHidden(h.ctx)\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 hidden: %w\", err)\n\t}\n\n\treturn ok, nil\n}\n\n// IsVisible checks if the element is visible.\nfunc (h *ElementHandle) IsVisible() (bool, error) {","sourceCodeStart":1073,"sourceCodeEnd":1109,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1073-L1109","documentation":"Returned by ElementHandle.isEnabled() when the state probe fails with a non-timeout error. ErrTimedOut is intentionally filtered out (timeout just yields 'not enabled yet' semantics), so this error means the probe itself broke: stale handle, destroyed execution context, CDP transport failure, or closed page/browser.","triggerScenarios":"Calling isEnabled() on a handle detached by re-render; after navigation destroyed the context; after page.close(); when the CDP session dropped.","commonSituations":"Buttons toggled by framework re-renders invalidating cached handles; probing right after an action that navigates; shutdown races at test end.","solutions":["Re-query the handle right before isEnabled()","Wait for the element to be attached","Check the page is still open before probing","try/catch around the probe to separate hard failures from false"],"exampleFix":"// before\nconst enabled = await h.isEnabled(); // stale handle\n// after\nconst el = await page.$('#submit');\nconst enabled = await el.isEnabled();","handlingStrategy":"try-catch","validationCode":"const el = await page.$('#submit');\nif (el && (await el.isVisible())) {\n  const enabled = await el.isEnabled();\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await handle.isEnabled();\n} catch (e) {\n  if (String(e).includes('checking element is enabled')) {\n    const fresh = await page.$(sel);\n    return fresh ? fresh.isEnabled() : false;\n  }\n  throw e;\n}","preventionTips":["False is a legitimate result; thrown errors are operational failures","Re-query handles before each state probe","Keep probes away from navigation/close boundaries"],"tags":["browser","element-handle","is-enabled","detached-handle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}