uploadFile
Uploads a file to the Selenium Standalone server or other browser driver
(e.g. Chromedriver) by using the file
command.
Note: that this command is only supported if you use a Selenium Hub or
Chromedriver directly.
Note: this command uses an un-offical protocol feature that is currently only supported in Chrome and when running a Selenium Grid.
Usage
browser.uploadFile(localPath)
Parameters
Name | Type | Details |
---|---|---|
localPath | String | local path to file |
Example
- Asynchronous Mode
- Synchronous Mode
uploadFile.js
const path = require('path');
it('should upload a file', async () => {
await browser.url('https://the-internet.herokuapp.com/upload')
const filePath = '/path/to/some/file.png'
const remoteFilePath = await browser.uploadFile(filePath)
await $('#file-upload').setValue(remoteFilePath)
await $('#file-submit').click()
});
uploadFile.js
const path = require('path');
it('should upload a file', () => {
browser.url('https://the-internet.herokuapp.com/upload')
const filePath = '/path/to/some/file.png'
const remoteFilePath = browser.uploadFile(filePath)
$('#file-upload').setValue(remoteFilePath)
$('#file-submit').click()
});
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.