Skip to navigation

upload

The upload action sets the files of a file input (<input type="file">). It replaces any files the input already holds. The operating system’s file dialog never opens, so the step runs unattended and headless.

Use it for a procedure step such as “Choose your avatar image”. A click on a file input fails, and type can’t fill one.

For comprehensive options, see the upload reference.

Properties

upload takes an object with path and at least one field that finds the element.

FieldTypeDescriptionDefault
pathstring or array of stringsRequired. File or files to set. A relative path resolves against the spec file, unless relativePathBase is cwd. Use an array only for an input that accepts several files.
selectorstringCSS or XPath selector of the file input or its label.
elementTextstringDisplay text of the file input’s label.
elementId, elementTestId, elementClass, elementAttribute, elementAriaas in clickOther ways to find the file input or its label. The element must match every field you set.
framestring or array of stringsSelector of the iframe that holds the input. See Elements inside an iframe.The top page
timeoutintegerMilliseconds to wait for the element. 0 checks once.5000
surfacestring or objectThe browser window or tab to use. See Test across multiple tabs, windows, and browsers.The active surface

Find the input

Many pages hide the file input and style its label as a button. upload works with a hidden input, so you can target either one:

  • The input, with selector, elementId, or elementTestId.
  • The label, with elementText. The step then uses the input that belongs to the label.

Some pages open the dialog from a script instead, so the button you see isn’t a label. Target the input itself, which is often hidden near the button.

A drop zone works when it has a file input behind it. If it has no file input, upload can’t fill it.

Platform support

upload works in desktop browsers. In a mobile browser, the step is SKIPPED, because the file isn’t on the device.

Outputs

OutputDescription
foundWhether the element exists.
filesAbsolute paths of the files, in order.

Failures

MessageFix
Couldn't upload `/abs/avatar.png`: the file doesn't exist.Check path. A relative path resolves against the spec file.
Couldn't upload: the element isn't a file input. Set `selector` to the `<input type="file">`.Target the input instead of the button that opens the dialog.
Couldn't upload 2 files: the file input accepts one. Set `path` to one file.Set one file, or check that the input has the multiple attribute.

Examples

Upload one file

{
"steps": [
{ "goTo": "https://app.example.com/profile" },
{ "upload": { "selector": "#avatar", "path": "avatar.png" } },
{ "find": "avatar.png" }
]
}

Upload several files through a label

{
"steps": [
{ "goTo": "https://app.example.com/expenses" },
{ "upload": { "elementText": "Choose files", "path": ["receipt-1.pdf", "receipt-2.pdf"] } },
{ "find": "receipt-2.pdf" }
]
}