{"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":1788,"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":1770,"sourceCodeEnd":1806,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L1770-L1806","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the element: await frame.waitForSelector('input[type=file]') and confirm it is a file input.","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').","If the input is hidden, click a visible label/button with { force: true } patterns or make the input visible via evaluate before setting files.","Increase timeout via opts if resolution is slow."],"exampleFix":"// before\nawait page.setInputFiles('#upload', 'file.pdf'); // relative path miss\n\n// after\nawait page.setInputFiles('#upload', '/home/me/data/file.pdf');","handlingStrategy":"validation","validationCode":"const ok = await frame.evaluate(s =>\n  document.querySelector(s)?.type === 'file', sel);\nif (!ok) throw new Error(`${sel} is not a file input`);\nimport { open } from 'k6/fs'; // or verify path readability before the call","typeGuard":"const isFileInput = (t) => t?.type === 'file';","tryCatchPattern":"try { await page.setInputFiles(sel, absPath); }\ncatch (e) { if (/setting input files on/.test(e.message)) { /* check element type, path, visibility */ } throw e; }","preventionTips":["Use absolute file paths — they resolve on the k6 host, not in the browser","Wait for the file input to exist before setting files","Un-hide styled file inputs via evaluate if actionability blocks"],"tags":["browser","upload","file-input","actionability","path"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}