{"record":{"id":"36692ac6e1c963d9","repo":"grafana/k6","slug":"clicking-the-checkbox-did-not-change-its-state","errorCode":null,"errorMessage":"clicking the checkbox did not change its state","messagePattern":"clicking the checkbox did not change its state","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1374,"sourceCode":"\tstate, err := h.checkElementState(apiCtx, \"checked\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tif checked == *state {\n\t\treturn nil\n\t}\n\n\terr = h.click(p, NewMouseClickOptions())\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tstate, err = h.checkElementState(apiCtx, \"checked\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tif checked != *state {\n\t\treturn errors.New(\"clicking the checkbox did not change its state\")\n\t}\n\n\treturn nil\n}\n\n// Screenshot will instruct Chrome to save a screenshot of the current element and save it to specified file.\nfunc (h *ElementHandle) Screenshot(\n\topts *ElementHandleScreenshotOptions,\n\tsp ScreenshotPersister,\n) ([]byte, error) {\n\tspanCtx, span := TraceAPICall(\n\t\th.ctx,\n\t\th.frame.page.targetID.String(),\n\t\t\"elementHandle.screenshot\",\n\t)\n\tdefer span.End()\n\n\tspan.SetAttributes(attribute.String(\"screenshot.path\", opts.Path))","sourceCodeStart":1356,"sourceCodeEnd":1392,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1356-L1392","documentation":"check()/uncheck()/setChecked() click the checkbox and then re-read its 'checked' state (element_handle.go:1355-1377). If the click completed but the state did not flip to the requested value, k6 reports that the click had no effect: 'clicking the checkbox did not change its state'.","triggerScenarios":"The selector targets a wrapper element (div/span with role=checkbox) instead of the real input; the input is disabled or readonly; an overlay or label intercepts the click; a controlled component (React/Vue) manages the checked property and reverts plain DOM clicks; the click toggles a different element than the one whose state is verified.","commonSituations":"Custom-designed checkboxes built from divs; React controlled inputs needing synthetic events; inputs disabled during form submission; animations or spinners covering the checkbox when clicked.","solutions":["Verify the selector resolves the actual input[type=checkbox] element, not its wrapper or label","Ensure the input is enabled and not readonly before calling check()/uncheck()","For framework-controlled widgets, click the real input directly or set the state via el.$eval('input', i => i.checked = true) followed by a change event","Pass a position option to click the exact checkbox area when an overlay is present"],"exampleFix":"// before\nconst box = await page.$('.fancy-checkbox'); // div, not input\nawait box.check(); // click lands, state unchanged\n\n// after\nconst box = await page.$('.fancy-checkbox input[type=checkbox]');\nawait box.check();","handlingStrategy":"retry","validationCode":"// Verify the target is a real, enabled checkbox before checking\nconst ok = await el.evaluate(node =>\n  node.tagName === 'INPUT' && node.type === 'checkbox' && !node.disabled && !node.readOnly\n);\nif (!ok) { /* fix the selector or use click/$eval instead */ }\nawait el.check();","typeGuard":null,"tryCatchPattern":"try {\n  await el.check();\n} catch (e) {\n  if (String(e.message).includes('did not change its state')) {\n    await el.$eval('input', i => { i.checked = true; i.dispatchEvent(new Event('change', { bubbles: true })); });\n  } else { throw e; }\n}","preventionTips":["Target the underlying input[type=checkbox], not its styled wrapper or label","Confirm the checkbox is enabled before check()/uncheck()","For framework-controlled inputs, set state via $eval plus a change event instead of check()"],"tags":["browser","checkbox","element-handle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}