grafana/k6 · error

setting input files on %q: %w

Error message

setting input files on %q: %w

What it means

Frame.SetInputFiles() wraps the internal action — resolving the element, actionability checks, and the CDP setFileInputFiles DOM call — as 'setting input files on "<selector>": <cause>'. The wrapped cause distinguishes element problems (timeout, not an <input type=file>) from upload problems (file unreadable, DOM.setFileInputFiles error).

Source

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

	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 93accf6570)

Solutions

  1. Verify the element: await frame.waitForSelector('input[type=file]') and confirm it is a file input.
  2. Use an absolute path for the file (or a correct path relative to where k6 runs) — e.g. await page.setInputFiles(sel, '/abs/path/file.pdf').
  3. If the input is hidden, click a visible label/button with { force: true } patterns or make the input visible via evaluate before setting files.
  4. Increase timeout via opts if resolution is slow.

Example fix

// before
await page.setInputFiles('#upload', 'file.pdf'); // relative path miss

// after
await page.setInputFiles('#upload', '/home/me/data/file.pdf');
Defensive patterns

Strategy: validation

Validate before calling

const ok = await frame.evaluate(s =>
  document.querySelector(s)?.type === 'file', sel);
if (!ok) throw new Error(`${sel} is not a file input`);
import { open } from 'k6/fs'; // or verify path readability before the call

Type guard

const isFileInput = (t) => t?.type === 'file';

Try / catch

try { await page.setInputFiles(sel, absPath); }
catch (e) { if (/setting input files on/.test(e.message)) { /* check element type, path, visibility */ } throw e; }

Prevention

When it happens

Trigger: Selector matches nothing or multiple nodes (strict mode); the matched element is not a file input; the Files payload references a local path that k6's process cannot read; the input is hidden and actionability fails; page navigated mid-action.

Common situations: Uploading with a wrong path relative to the k6 process CWD (paths are resolved server-side, not browser-side); hidden file inputs styled away by CSS; file inputs inside shadow DOM requiring piercing selectors.

Related errors


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