grafana/k6 · error

setting checked %q: %w

Error message

setting checked %q: %w

What it means

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.

Source

Thrown at internal/js/modules/k6/browser/common/frame.go:693

	setChecked := func(apiCtx context.Context, handle *ElementHandle, p *Position) (any, error) {
		return nil, handle.setChecked(apiCtx, checked, p)
	}
	act := f.newPointerAction(
		selector, DOMElementStateAttached, opts.Strict, setChecked, &opts.ElementHandleBasePointerOptions,
	)
	if _, err := call(f.ctx, act, opts.Timeout); err != nil {
		return errorFromDOMError(err)
	}

	return nil
}

// SetChecked sets the checked state of the first element found that matches the selector.
func (f *Frame) SetChecked(selector string, checked bool, popts *FrameCheckOptions) error {
	f.log.Debugf("Frame:SetChecked", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)

	if err := f.setChecked(selector, checked, popts); err != nil {
		return fmt.Errorf("setting checked %q: %w", selector, err)
	}

	applySlowMo(f.ctx)

	return nil
}

// Uncheck the first found element that matches the selector.
func (f *Frame) Uncheck(selector string, popts *FrameUncheckOptions) error {
	f.log.Debugf("Frame:Uncheck", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)

	if err := f.uncheck(selector, popts); err != nil {
		return fmt.Errorf("unchecking %q: %w", selector, err)
	}

	applySlowMo(f.ctx)

	return nil

View on GitHub (pinned to 93accf6570)

Solutions

  1. Verify the element is an <input type=checkbox|radio> and use a unique selector.
  2. Increase the timeout option and wait for visible state first.
  3. For re-render churn, retry the operation once after waiting for the element again.

Example fix

// before
frame.setChecked('#terms', true, { timeout: 1000 });

// after
await frame.waitForSelector('#terms', { state: 'visible', timeout: 30000 });
frame.setChecked('#terms', true, { timeout: 30000 });
Defensive patterns

Strategy: validation

Validate before calling

await frame.waitForSelector(sel, { state: 'visible', timeout: 30000 });
const editable = await frame.evaluate('(s) => { const el = document.querySelector(s); return !!el && !el.disabled && /checkbox|radio/.test(el.type || ""); }', sel);

Try / catch

try {
  frame.setChecked(sel, true, { timeout: 30000 });
} catch (e) {
  if (/not a checkbox/.test(e.message)) { /* wrong element kind — fix selector */ }
}

Prevention

When it happens

Trigger: 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.

Common situations: Framework-driven re-renders (React re-mounts the input mid-action); hidden native inputs behind custom components; short timeouts in CI.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/c822cd7b90af8148. Report an issue: GitHub.