{"record":{"id":"38cf16c8fbc11105","repo":"grafana/k6","slug":"checking-element-is-disabled-w","errorCode":null,"errorMessage":"checking element is disabled: %w","messagePattern":"checking element is disabled: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1069,"sourceCode":"}\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) {\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) {","sourceCodeStart":1051,"sourceCodeEnd":1087,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L1051-L1087","documentation":"ElementHandle.isDisabled() runs waitForElementState(['disabled']) with a zero timeout and ignores ErrTimedOut by design. The wrapped error therefore comes from the injected script or CDP layer: a detached element handle, an execution context destroyed by navigation, or a closed session - not from the element simply being enabled.","triggerScenarios":"The element node was replaced by a re-render after the handle was acquired; navigation destroyed the execution context; the frame or page containing the element closed; the CDP session stalled.","commonSituations":"Forms whose controls are recreated during multi-step wizards; SPAs re-rendering disabled/enabled buttons on state changes; handles cached from earlier screens.","solutions":["Re-acquire the element or use page.locator(sel).isDisabled() which re-resolves the node","Treat thrown errors as 'element gone' via try/catch when the check is advisory","Verify attachment first: await el.evaluate(e => e.isConnected)","Do not store handles across page.goto() or long async flows"],"exampleFix":"// before\nconst el = await page.$('#submit');\nawait flowThatReplacesTheButton();\nconst disabled = await el.isDisabled(); // throws: node replaced\n\n// after\nawait flowThatReplacesTheButton();\nconst disabled = await page.locator('#submit').isDisabled();","handlingStrategy":"try-catch","validationCode":"// Re-resolve state with a live query\nconst disabled = (await page.$(sel)) === null\n  ? true // gone implies not interactable in most test semantics\n  : await page.locator(sel).isDisabled();","typeGuard":null,"tryCatchPattern":"let disabled = false;\ntry {\n  disabled = await el.isDisabled();\n} catch (e) {\n  if (/not attached|Execution context|Could not find object/i.test(String(e.message))) {\n    disabled = await page.locator(sel).isDisabled();\n  } else throw e;\n}","preventionTips":["Use locators for state assertions so the node is re-resolved each call","Never cache handles across multi-step flows that rebuild forms","Note isDisabled() returns false for a live enabled element; only transport errors throw"],"tags":["browser","element-state","disabled","stale-element","k6"],"backgroundTag":"stale-element-reference","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"}