{"record":{"id":"3cea9e7e66eebd30","repo":"grafana/k6","slug":"checking-element-is-checked-q-w","errorCode":null,"errorMessage":"checking element is checked %q: %w","messagePattern":"checking element is checked %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":735,"sourceCode":"\t}\n\tact := f.newPointerAction(\n\t\tselector, DOMElementStateAttached, opts.Strict, uncheck, &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// IsChecked returns true if the first element that matches the selector\n// is checked. Otherwise, returns false.\nfunc (f *Frame) IsChecked(selector string, opts *FrameIsCheckedOptions) (bool, error) {\n\tf.log.Debugf(\"Frame:IsChecked\", \"fid:%s furl:%q sel:%q\", f.ID(), f.URL(), selector)\n\n\tchecked, err := f.isChecked(selector, opts)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"checking element is checked %q: %w\", selector, err)\n\t}\n\n\treturn checked, nil\n}\n\nfunc (f *Frame) isChecked(selector string, opts *FrameIsCheckedOptions) (bool, error) {\n\tisChecked := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\tv, err := handle.isChecked(apiCtx, 0) // Zero timeout when checking state\n\t\tif errors.Is(err, ErrTimedOut) {      // We don't care about timeout errors here!\n\t\t\treturn v, nil\n\t\t}\n\t\treturn v, err\n\t}\n\tact := f.newAction(\n\t\tselector, DOMElementStateAttached, opts.Strict, isChecked, []string{}, false, withRetry, true, opts.Timeout,\n\t)\n\tv, err := call(f.ctx, act, opts.Timeout)\n\tif err != nil {","sourceCodeStart":717,"sourceCodeEnd":753,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L717-L753","documentation":"Frame.IsChecked() runs an action that waits for an element matching the selector to be attached (within opts.Timeout) and then queries its checked state. This error wraps failures of that wait/action — most often 'waiting for selector ... timed out' when no element attaches in time, converted via errorFromDOMError.","triggerScenarios":"Selector matches nothing within the timeout (element not attached); strict-mode multiple matches; frame navigating so the execution context is destroyed during the wait.","commonSituations":"Checking state of an element that renders conditionally after an async action (fetch completes late); asserting on the wrong frame; short timeouts during CI slowness.","solutions":["Wait for the element to be attached before querying: waitForSelector(sel, { state: 'attached' }).","Increase opts.Timeout.","Use a unique selector and the correct frame (page vs iframe)."],"exampleFix":"// before\nconst ok = frame.isChecked('#agree', { timeout: 2000 });\n\n// after\nawait frame.waitForSelector('#agree', { state: 'attached', timeout: 30000 });\nconst ok = frame.isChecked('#agree', { timeout: 30000 });","handlingStrategy":"try-catch","validationCode":"await frame.waitForSelector(sel, { state: 'attached', timeout: 30000 });","typeGuard":null,"tryCatchPattern":"let checked = false;\ntry {\n  checked = frame.isChecked(sel, { timeout: 30000 });\n} catch (e) {\n  console.warn(`isChecked(${sel}) failed, treating as false:`, e.message);\n}","preventionTips":["Wait for the element to attach before querying state.","Pass explicit timeouts instead of relying on defaults in slow environments.","Query the correct frame."],"tags":["browser","ischecked","selector","timeout","wait"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}