{"record":{"id":"3b51f3789d759e41","repo":"grafana/k6","slug":"setting-input-files-w","errorCode":null,"errorMessage":"setting input files: %w","messagePattern":"setting input files: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1461,"sourceCode":"\t\t[]string{}, selectText, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tif _, err := call(h.ctx, selectTextAction, opts.Timeout); err != nil {\n\t\treturn fmt.Errorf(\"selecting text: %w\", err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn nil\n}\n\n// SetInputFiles sets the given files into the input file element.\nfunc (h *ElementHandle) SetInputFiles(files *Files, opts *ElementHandleSetInputFilesOptions) error {\n\tsetInputFiles := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn nil, handle.setInputFiles(apiCtx, files)\n\t}\n\tsetInputFilesAction := h.newAction([]string{}, setInputFiles, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout)\n\tif _, err := call(h.ctx, setInputFilesAction, opts.Timeout); err != nil {\n\t\treturn fmt.Errorf(\"setting input files: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (h *ElementHandle) setInputFiles(apiCtx context.Context, files *Files) error {\n\t// allow clearing the input by passing an empty array\n\tvar payload []*File\n\tif files != nil {\n\t\tpayload = files.Payload\n\t}\n\tfn := `\n\t\t(node, injected, payload) => {\n\t\t\treturn injected.setInputFiles(node, payload);\n\t\t}\n\t`\n\tevalOpts := evalOptions{\n\t\tforceCallable: true,","sourceCodeStart":1443,"sourceCodeEnd":1479,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1443-L1479","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\npage.$('#upload-button').setInputFiles([{ name: 'a.png', mimeType: 'image/png', buffer: btoa('...') }]);\n// fails: node is not an input[type=file] element\n\n// after\nconst input = page.waitForSelector('input[type=file]', { state: 'attached' });\ninput.setInputFiles([{ name: 'a.png', mimeType: 'image/png', buffer: pngBase64 }]);","handlingStrategy":"validation","validationCode":"const input = page.waitForSelector('input[type=file]', { state: 'attached' });\nconst isMultiple = input.evaluate((n) => n.multiple);\nconst files = [{ name: 'a.png', mimeType: 'image/png', buffer: pngBase64 }];\nif (files.length > 1 && !isMultiple) {\n  throw new Error('target input does not accept multiple files');\n}\ninput.setInputFiles(files);","typeGuard":null,"tryCatchPattern":"try {\n  input.setInputFiles(files);\n} catch (e) {\n  if (String(e).includes('setting input files')) {\n    // check DOM error text: 'not input[type=file]' vs 'multiple file'\n    throw new Error(`setInputFiles failed: ${e}`);\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["browser","file-upload","dom","actionability","element-handle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}