{"record":{"id":"4ee7f50e6ce4da39","repo":"grafana/k6","slug":"checking-element-w","errorCode":null,"errorMessage":"checking element: %w","messagePattern":"checking element: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1335,"sourceCode":"\t\treturn cmp.Compare(a.index, b.index)\n\t})\n\n\tels := make([]*ElementHandle, 0, len(indexedElems))\n\tfor _, ie := range indexedElems {\n\t\tels = append(els, ie.elem)\n\t}\n\n\treturn els, nil\n}\n\n// SetChecked checks or unchecks an element.\nfunc (h *ElementHandle) SetChecked(checked bool, opts *ElementHandleSetCheckedOptions) error {\n\tsetChecked := func(apiCtx context.Context, handle *ElementHandle, p *Position) (any, error) {\n\t\treturn nil, handle.setChecked(apiCtx, checked, p)\n\t}\n\tsetCheckedAction := h.newPointerAction(setChecked, &opts.ElementHandleBasePointerOptions)\n\tif _, err := call(h.ctx, setCheckedAction, opts.Timeout); err != nil {\n\t\treturn fmt.Errorf(\"checking element: %w\", err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn nil\n}\n\n// Uncheck scrolls element into view, and if it's an input element of type\n// checkbox that is already checked, clicks on it to mark it as unchecked.\nfunc (h *ElementHandle) Uncheck(opts *ElementHandleSetCheckedOptions) error {\n\treturn h.SetChecked(false, opts)\n}\n\n// Check scrolls element into view, and if it's an input element of type\n// checkbox that is unchecked, clicks on it to mark it as checked.\nfunc (h *ElementHandle) Check(opts *ElementHandleSetCheckedOptions) error {\n\treturn h.SetChecked(true, opts)\n}","sourceCodeStart":1317,"sourceCodeEnd":1353,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1317-L1353","documentation":"ElementHandle.SetChecked() (and Uncheck(), which delegates to it) wraps every failure of the check/uncheck pointer action (element_handle.go:1335). The wrapped error is most often the injected script's 'not a checkbox or radio button' (error:notcheckbox), an actionability timeout (hidden/disabled/unstable element), or a detached handle.","triggerScenarios":"Calling check() on anything other than input[type=checkbox] or input[type=radio]; the input is hidden (custom-styled controls), disabled, or animating past the timeout; label-wrapped custom checkboxes where the real input is visually hidden.","commonSituations":"Modern UI kits that hide the native input and style a span — check() times out or Playwright-style force is needed; forms rendered after async fetch with default timeouts too small.","solutions":["Confirm the target is a real input[type=checkbox|radio] (inspect DOM); target the input, not the styled label/span","waitForSelector with state:'visible' first, or raise opts.timeout","If the native input is intentionally visually hidden but functional, use { force: true } or check via label click","Verify enabled state — disabled inputs fail actionability"],"exampleFix":"// before\nawait page.$('.fancy-toggle').check(); // styled span, not the input\n// after\nawait page.$('input[type=checkbox]#consent').check({ timeout: 10_000 });","handlingStrategy":"validation","validationCode":"// Verify the target is a real checkbox/radio input before checking\nconst is = await el.evaluate(n => n.tagName === 'INPUT' && ['checkbox','radio'].includes(n.type));\nif (!is) throw new Error('not a checkbox/radio input — use click() for custom controls');","typeGuard":"const isCheckable = async el => await el.evaluate(n => n.tagName === 'INPUT' && (n.type === 'checkbox' || n.type === 'radio'));","tryCatchPattern":"try { await el.check({ timeout: 10_000 }); }\ncatch (e) {\n  if (/checking element/.test(e.message) && /not a checkbox/.test(e.message)) { await el.click(); /* custom control */ }\n  else if (/waiting/.test(e.message)) { await page.waitForSelector(sel, { state: 'visible' }); await el.check({ force: true }); }\n  else throw e;\n}","preventionTips":["Target the native input, not the styled span/label","Wait for visible state and enabled inputs","Use force only for intentionally-hidden native inputs"],"tags":["browser","form","actionability","checkbox"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}