input.setFiles commandThe input.setFiles command of the input module simulates a file picker dialog by setting the file selection of an <input type="file"> element in a given context to the specified file paths.
{
"method": "input.setFiles",
"params": {
"context": "5f07e3ca-ecac-465e-b9ef-49000c196ecf",
"element": {
"sharedId": "3be28343-afd3-4dea-a2b6-a863fbbb80e1"
},
"files": ["/home/user/documents/report.pdf"]
}
}The params field contains:
contextA string that contains the ID of the context with the target <input type="file"> element. Context IDs are returned by commands such as browsingContext.getTree.
elementAn object containing the ID that uniquely identifies the <input type="file"> DOM element to use for file selection. The ID is returned by the browser when you locate the element using browsingContext.locateNodes, script.evaluate, or script.callFunction.
filesAn array of strings, where each string is the absolute file path of a file to select. This command overrides any previously selected files. You can pass an empty array to clear the selection. If the array contains more than one file path, ensure that the <input type="file"> element has the multiple attribute.
The result field in the response is an empty object ({}).
invalid argumentA required parameter is missing or has an invalid type.
no such elementThe element reference cannot be resolved to a valid DOM element in the given context.
no such frameNo context with the given context ID is found.
unable to set file inputThe element is not an <input> element with type="file", the element is disabled, or more than one file path is provided without the multiple attribute.
unsupported operationThe browser is unable to set the selected files to the provided paths; for example, if any of the specified files do not exist on the filesystem.
With a WebDriver BiDi connection and an active session, first obtain the sharedId of an <input type="file"> element using browsingContext.locateNodes or an input.fileDialogOpened event, then send the following message to set its selected file:
{
"id": 1,
"method": "input.setFiles",
"params": {
"context": "5f07e3ca-ecac-465e-b9ef-49000c196ecf",
"element": {
"sharedId": "3be28343-afd3-4dea-a2b6-a863fbbb80e1"
},
"files": ["/home/user/documents/test-upload.txt"]
}
}The browser responds as follows:
{
"id": 1,
"type": "success",
"result": {}
}To clear all previously selected files, pass an empty array:
{
"id": 2,
"method": "input.setFiles",
"params": {
"context": "5f07e3ca-ecac-465e-b9ef-49000c196ecf",
"element": {
"sharedId": "3be28343-afd3-4dea-a2b6-a863fbbb80e1"
},
"files": []
}
}The browser responds as follows:
{
"id": 2,
"type": "success",
"result": {}
}input.performActions commandinput.releaseActions commandinput.fileDialogOpened eventscript.evaluate command