{"record":{"id":"bc349fb2dbc4104f","repo":"grafana/k6","slug":"setting-input-files-on-q-w","errorCode":null,"errorMessage":"setting input files on %q: %w","messagePattern":"setting input files on %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":1796,"sourceCode":"\teopts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,\n\t}\n\tif _, err := f.evaluate(f.ctx, utilityWorld, eopts, js, html); err != nil {\n\t\treturn fmt.Errorf(\"setting content: %w\", err)\n\t}\n\n\tapplySlowMo(f.ctx)\n\n\treturn nil\n}\n\n// SetInputFiles sets input files for the selected element.\nfunc (f *Frame) SetInputFiles(selector string, pfiles *Files, popts *FrameSetInputFilesOptions) error {\n\tf.log.Debugf(\"Frame:SetInputFiles\", \"fid:%s furl:%q sel:%q\", f.ID(), f.URL(), selector)\n\n\tif err := f.setInputFiles(selector, pfiles, popts); err != nil {\n\t\treturn fmt.Errorf(\"setting input files on %q: %w\", selector, err)\n\t}\n\n\tapplySlowMo(f.ctx)\n\n\treturn nil\n}\n\n// Tap the first element that matches the selector.\nfunc (f *Frame) Tap(selector string, opts *FrameTapOptions) error {\n\tf.log.Debugf(\"Frame:Tap\", \"fid:%s furl:%q sel:%q\", f.ID(), f.URL(), selector)\n\n\tif err := f.tap(selector, opts); err != nil {\n\t\treturn fmt.Errorf(\"tapping on %q: %w\", selector, err)\n\t}\n\n\tapplySlowMo(f.ctx)\n\n\treturn nil","sourceCodeStart":1778,"sourceCodeEnd":1814,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L1778-L1814","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Confirm the target: page.$eval(sel, el => ({ type: el.type, multiple: el.multiple }))","Reveal/enable the input before the call, or use force:true if only visibility blocks it","Match the file count to the input's `multiple` attribute","Wait for the input to be attached: page.waitForSelector(sel, { state: 'attached' })"],"exampleFix":"// before\npage.setInputFiles('input[type=file]', [{ name: 'a.csv', mimeType: 'text/csv', data: b64 }]);\n\n// after\npage.waitForSelector('input[type=file]', { state: 'attached', timeout: 10000 });\nconst meta = page.$eval('input[type=file]', el => ({ type: el.type, multiple: el.multiple }));\nif (meta.type !== 'file') throw new Error('not a file input');\npage.setInputFiles('input[type=file]', [{ name: 'a.csv', mimeType: 'text/csv', data: b64 }]);","handlingStrategy":"validation","validationCode":"page.waitForSelector(sel, { state: 'attached', timeout: 10000 });\nconst meta = page.$eval(sel, el => ({ tag: el.tagName, type: el.type, multiple: el.multiple }));\nif (meta.tag !== 'INPUT' || meta.type !== 'file') throw new Error(`${sel} is not a file input`);\nif (!meta.multiple && files.length > 1) throw new Error('input does not accept multiple files');","typeGuard":null,"tryCatchPattern":"try {\n  page.setInputFiles(sel, files);\n} catch (e) {\n  throw new Error(`setInputFiles('${sel}') failed — verify <input type=file> exists, is reachable, and file list matches 'multiple': ${e}`);\n}","preventionTips":["Confirm the input's type and multiple attributes before every upload step","Reveal hidden upload widgets (click the upload button) before setInputFiles","Keep each file's name/mimeType/data well-formed"],"tags":["k6","browser","file-upload","input","timeout"],"backgroundTag":"invalid-input-file","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}