{"record":{"id":"c822cd7b90af8148","repo":"grafana/k6","slug":"setting-checked-q-w","errorCode":null,"errorMessage":"setting checked %q: %w","messagePattern":"setting checked %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":693,"sourceCode":"\tsetChecked := func(apiCtx context.Context, handle *ElementHandle, p *Position) (any, error) {\n\t\treturn nil, handle.setChecked(apiCtx, checked, p)\n\t}\n\tact := f.newPointerAction(\n\t\tselector, DOMElementStateAttached, opts.Strict, setChecked, &opts.ElementHandleBasePointerOptions,\n\t)\n\tif _, err := call(f.ctx, act, opts.Timeout); err != nil {\n\t\treturn errorFromDOMError(err)\n\t}\n\n\treturn nil\n}\n\n// SetChecked sets the checked state of the first element found that matches the selector.\nfunc (f *Frame) SetChecked(selector string, checked bool, popts *FrameCheckOptions) error {\n\tf.log.Debugf(\"Frame:SetChecked\", \"fid:%s furl:%q sel:%q\", f.ID(), f.URL(), selector)\n\n\tif err := f.setChecked(selector, checked, popts); err != nil {\n\t\treturn fmt.Errorf(\"setting checked %q: %w\", selector, err)\n\t}\n\n\tapplySlowMo(f.ctx)\n\n\treturn nil\n}\n\n// Uncheck the first found element that matches the selector.\nfunc (f *Frame) Uncheck(selector string, popts *FrameUncheckOptions) error {\n\tf.log.Debugf(\"Frame:Uncheck\", \"fid:%s furl:%q sel:%q\", f.ID(), f.URL(), selector)\n\n\tif err := f.uncheck(selector, popts); err != nil {\n\t\treturn fmt.Errorf(\"unchecking %q: %w\", selector, err)\n\t}\n\n\tapplySlowMo(f.ctx)\n\n\treturn nil","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L675-L711","documentation":"Frame.SetChecked() waits for the element to be actionable and sets its checked state to the requested boolean via handle.setChecked. This error wraps the underlying failure: wait timeout, 'element is not a checkbox or radio button', or element detached/not-connected DOM errors.","triggerScenarios":"Passing a selector for a non-checkable element; element not visible/stable within opts.Timeout; strict-mode ambiguity; element re-rendered (not connected) between wait and the set operation.","commonSituations":"Framework-driven re-renders (React re-mounts the input mid-action); hidden native inputs behind custom components; short timeouts in CI.","solutions":["Verify the element is an <input type=checkbox|radio> and use a unique selector.","Increase the timeout option and wait for visible state first.","For re-render churn, retry the operation once after waiting for the element again."],"exampleFix":"// before\nframe.setChecked('#terms', true, { timeout: 1000 });\n\n// after\nawait frame.waitForSelector('#terms', { state: 'visible', timeout: 30000 });\nframe.setChecked('#terms', true, { timeout: 30000 });","handlingStrategy":"validation","validationCode":"await frame.waitForSelector(sel, { state: 'visible', timeout: 30000 });\nconst editable = await frame.evaluate('(s) => { const el = document.querySelector(s); return !!el && !el.disabled && /checkbox|radio/.test(el.type || \"\"); }', sel);","typeGuard":null,"tryCatchPattern":"try {\n  frame.setChecked(sel, true, { timeout: 30000 });\n} catch (e) {\n  if (/not a checkbox/.test(e.message)) { /* wrong element kind — fix selector */ }\n}","preventionTips":["Confirm target is an enabled checkbox/radio before setChecked.","Use unique selectors to avoid strict-mode failures.","Retry once when the framework re-mounts inputs."],"tags":["browser","setchecked","checkbox","selector","timeout"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}