page.on('filechooser') event or by interacting with file input elements directly.
Overview
Methods
element()
Get the input element associated with the file chooser. Returns:ElementHandle
isMultiple()
Check if the file chooser accepts multiple files. Returns:boolean
Returns true if the input element has the multiple attribute:
page()
Get the page that opened the file chooser. Returns:Page
setFiles(files, options?)
Set files for the file chooser.string | FilePayload | string[] | FilePayload[]
required
Path(s) to file(s) or file payload object(s) to upload
number
Maximum time in milliseconds. Defaults to 30000 (30 seconds).
boolean
default:"false"
If set, don’t wait for the file input to be processed after setting files.
Promise<void>
File Path
File Payload
Clear Files
Examples
Basic File Upload
Upload Multiple Files
Upload from Buffer
Direct Input Element Upload
Check Accepted File Types
Cancel File Selection
Upload with Form Submit
Generate Dynamic File
Verify Upload
Best Practices
Wait Before Triggering
Set up the file chooser listener before the action:Use Promise.all
Check Multiple Attribute
Verify if multiple files are expected:Use setInputFiles for Simple Cases
If you don’t need to intercept the file chooser dialog:Verify File Type
Check accepted file types before uploading:Common Issues
File Chooser Not Triggered
Ensure the file input is properly activated:Hidden File Inputs
Some file inputs are hidden with CSS:File Path Issues
Use absolute paths or paths relative to the test file:Type Definitions
FilePayload
Related
- Page - Page object
- ElementHandle - Element handle API
- Download - File download API
