grafana/k6 · error

setting input files on

Error message

setting input files on %q: %w

What it means

Wrapper error from k6 browser's frame.SetInputFiles(selector, files): the wait-for-element plus set-files action failed. The wrapped cause is usually a selector timeout, or the matched element not being a valid file input for the given files.

Solutions

  1. Confirm the target: page.$eval(sel, el => ({ type: el.type, multiple: el.multiple }))
  2. Reveal/enable the input before the call, or use force:true if only visibility blocks it
  3. Match the file count to the input's `multiple` attribute
  4. Wait for the input to be attached: page.waitForSelector(sel, { state: 'attached' })

Example fix

// before
page.setInputFiles('input[type=file]', [{ name: 'a.csv', mimeType: 'text/csv', data: b64 }]);

// after
page.waitForSelector('input[type=file]', { state: 'attached', timeout: 10000 });
const meta = page.$eval('input[type=file]', el => ({ type: el.type, multiple: el.multiple }));
if (meta.type !== 'file') throw new Error('not a file input');
page.setInputFiles('input[type=file]', [{ name: 'a.csv', mimeType: 'text/csv', data: b64 }]);
Defensive patterns

Strategy: validation

Validate before calling

page.waitForSelector(sel, { state: 'attached', timeout: 10000 });
const meta = page.$eval(sel, el => ({ tag: el.tagName, type: el.type, multiple: el.multiple }));
if (meta.tag !== 'INPUT' || meta.type !== 'file') throw new Error(`${sel} is not a file input`);
if (!meta.multiple && files.length > 1) throw new Error('input does not accept multiple files');

Try / catch

try {
  page.setInputFiles(sel, files);
} catch (e) {
  throw new Error(`setInputFiles('${sel}') failed — verify <input type=file> exists, is reachable, and file list matches 'multiple': ${e}`);
}

Prevention

When it happens

Trigger: page.setInputFiles(sel, files) where the selector matches nothing within the timeout, matches multiple elements in strict mode, or the element is not an <input type="file"> (or lacks `multiple` when several files are given, or the files payload is invalid).

Common situations: Upload flows where the file input is hidden until a button click reveals it; drag-and-drop styled uploaders that use no real input; passing an array of files to a single-file input.

Related errors


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18). Data as JSON: /api/errors/bc349fb2dbc4104f. Report an issue: GitHub.

Appendix: source

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

	eopts := evalOptions{
		forceCallable: true,
		returnByValue: true,
	}
	if _, err := f.evaluate(f.ctx, utilityWorld, eopts, js, html); err != nil {
		return fmt.Errorf("setting content: %w", err)
	}

	applySlowMo(f.ctx)

	return nil
}

// SetInputFiles sets input files for the selected element.
func (f *Frame) SetInputFiles(selector string, pfiles *Files, popts *FrameSetInputFilesOptions) error {
	f.log.Debugf("Frame:SetInputFiles", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)

	if err := f.setInputFiles(selector, pfiles, popts); err != nil {
		return fmt.Errorf("setting input files on %q: %w", selector, err)
	}

	applySlowMo(f.ctx)

	return nil
}

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

	if err := f.tap(selector, opts); err != nil {
		return fmt.Errorf("tapping on %q: %w", selector, err)
	}

	applySlowMo(f.ctx)

	return nil

View on GitHub (pinned to 3fcf5388d7)