grafana/k6 · error
setting input files: %w
Error message
setting input files: %w
What it means
Wrapped failure from ElementHandle.SetInputFiles (elementHandle.setInputFiles()). The inner error comes from setInputFiles evaluating an injected-script payload in the page: the node is not an <input type=file> element, a non-multiple input got more than one file, the element is detached/hidden, or the action timed out. The 'setting input files:' prefix identifies the failing step.
Source
Thrown at internal/js/modules/k6/browser/common/element_handle.go:1461
[]string{}, selectText, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,
)
if _, err := call(h.ctx, selectTextAction, opts.Timeout); err != nil {
return fmt.Errorf("selecting text: %w", err)
}
applySlowMo(h.ctx)
return nil
}
// SetInputFiles sets the given files into the input file element.
func (h *ElementHandle) SetInputFiles(files *Files, opts *ElementHandleSetInputFilesOptions) error {
setInputFiles := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
return nil, handle.setInputFiles(apiCtx, files)
}
setInputFilesAction := h.newAction([]string{}, setInputFiles, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout)
if _, err := call(h.ctx, setInputFilesAction, opts.Timeout); err != nil {
return fmt.Errorf("setting input files: %w", err)
}
return nil
}
func (h *ElementHandle) setInputFiles(apiCtx context.Context, files *Files) error {
// allow clearing the input by passing an empty array
var payload []*File
if files != nil {
payload = files.Payload
}
fn := `
(node, injected, payload) => {
return injected.setInputFiles(node, payload);
}
`
evalOpts := evalOptions{
forceCallable: true,View on GitHub (pinned to 93accf6570)
Solutions
- Target the actual input[type=file] element, e.g. page.waitForSelector('input[type=file]', { state: 'visible' }) — use { omitDefaultContent: true } frame scoping if it is inside an iframe
- Pass only one file unless the input has the multiple attribute
- Increase opts.Timeout if the input appears late
- To clear the input, call setInputFiles([]) with an empty payload instead of removing the element
Example fix
// before
page.$('#upload-button').setInputFiles([{ name: 'a.png', mimeType: 'image/png', buffer: btoa('...') }]);
// fails: node is not an input[type=file] element
// after
const input = page.waitForSelector('input[type=file]', { state: 'attached' });
input.setInputFiles([{ name: 'a.png', mimeType: 'image/png', buffer: pngBase64 }]); Defensive patterns
Strategy: validation
Validate before calling
const input = page.waitForSelector('input[type=file]', { state: 'attached' });
const isMultiple = input.evaluate((n) => n.multiple);
const files = [{ name: 'a.png', mimeType: 'image/png', buffer: pngBase64 }];
if (files.length > 1 && !isMultiple) {
throw new Error('target input does not accept multiple files');
}
input.setInputFiles(files); Try / catch
try {
input.setInputFiles(files);
} catch (e) {
if (String(e).includes('setting input files')) {
// check DOM error text: 'not input[type=file]' vs 'multiple file'
throw new Error(`setInputFiles failed: ${e}`);
}
throw e;
} Prevention
- Scope selectors to input[type=file], never to the styled upload button
- Check the multiple attribute before sending a list of files
- Use setInputFiles([]) to clear, rather than interacting with the widget UI
When it happens
Trigger: Calling setInputFiles on a node that is not input[type=file] (error:notfile); passing multiple files in Files.Payload to an input without the multiple attribute (error:notmultiplefileinput); element detached by re-render; opts.Timeout exceeded before the input becomes actionable.
Common situations: File-upload forms where the real <input type=file> is hidden and a styled button triggers it — scripts target the button instead; uploading several files to a single-file input; file upload widgets inside iframes requiring frame-scoped queries.
Related errors
- selecting text: %w
- element is not attached to the DOM
- parsing setInputFiles parameter: %w
- finding clickable point: %w
- filling element: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/3b51f3789d759e41.
Report an issue: GitHub.