Wait for Download
Wait for Download
Section titled “Wait for Download”Type: page-wait-for-download · Package: Browser v1.0.9 · Output: string
Downloads a file from the page reliably. You wrap inside its body the action that triggers the download (a click on “Download”, a PDF/Excel export link) and the activity waits for the download to finish, returning the full path of the saved file.
It solves a classic problem: if you just click “Download” and move on, the file may not have finished downloading when the next activity tries to open it. This activity synchronizes both.
How it works
Section titled “How it works”- It starts “listening” for downloads on the
sessiontab. - It runs the activities in the
body(which trigger the download). - It waits for the download to start, up to
timeout; then it waits for it to finish, with no time limit. - It saves it to
outputPathand returns the full path of the saved file.
- If
outputPathis a folder, the file is named as the site suggests (the name you would see in the browser). It’s treated as a folder if it already exists as a folder, if it ends in\or/, or if it has no extension; otherwise, as a file path. - Missing folders are created automatically and a file with the same name is overwritten.
- It only listens on the
sessiontab: if the download comes from another tab (a pop-up window), pass that tab’s session. - The activities in the
bodydo not inheritsession: they use the page of the Open Browserbodythat contains them, or the one you pass inpage.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanPageSession | — | The session of the tab where the download happens. Pass page; it isn’t inherited from the body. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
outputPath | string | temp folder | Folder or file path to save to. If you give a folder, the name suggested by the site is used. Empty: the system temp folder. |
timeout | number | 30000 | Maximum time in ms to wait for the download to start. 0 or negative: the default. It doesn’t use the project timeout. |
Sub-flows
Section titled “Sub-flows”Optional. The activities that trigger the download (a click on the download button, an export link). If you leave it empty, the activity just waits for a download that starts some other way.
Output
Section titled “Output”Returns a string with the full path of the downloaded file, e.g. C:\Downloads\reports\sales.xlsx.
Example
Section titled “Example”Export a report to Excel and get its path to process it:
Wait for Download session = page outputPath = "C:\Downloads\reports" → output: rutaReporte └─ body: Page Click page = page selector = (#exportarExcel)
Excel Open path = rutaReporte → output: libroCommon errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
'session' must be a ZoanPageSession. | session is empty or doesn’t hold a page session. Pass page (even if you’re inside a body). |
Timeout 30000ms exceeded … waiting for the download | No download started in time: the click didn’t trigger it, it opened in another tab or the site displayed it in the browser. Check the body action, raise timeout or use Download File if you have the URL. |
| Error saving the file | The path doesn’t allow writing or the file is open in another program (e.g. Excel). Close it or use another path. |
Related activities
Section titled “Related activities”- Click — the typical action inside the
body. - Download File — when you already have the file’s URL.
- Excel Open / Read File — process the downloaded file.