Icon

Selenium-Download-File-36994

This workflow demonstrates how to handle file downloads with Selenium Nodes and a Chrome-based browser.

It's a rather sophisticated way of handling a file download which is due to the following points:

(1) Instead of just using a hard-coded download location in the JSON snippet (see Start WebDriver -> Snippets), it will use a system-specific temporary directory to ensure that it works acroess different operating systems

(2) After the download has been started, the workflow will continuously check if the download is still running. This is important especially for larger files. It does not use a “dumb” wait timeout of X seconds, but instead dynamically checks when the download has finished.

The example workflow will go to the Palladian page on NodePit (https://nodepit.com/product/palladian) and download the update site ZIP file. Adapt as needed :-)

URL: Forum Post https://forum.knime.com/t/save-as-windows-file-dialogue-clickable-by-se-nodes/36994

Build “Capabilities” JSON for the Start WebDriver node.It'll use a temporary directoy for the file download instead of hard-codingit into the JSON editor. Thus the workflow remains portable acrossdifferent environments and operating systems. The download has started now. But did it already finish?To check if the file has been completely downloaded, run a loop which will continuously check, if thedownload is complete. While the download is running, there's a temporary file which endswith .crdownload -- when it's finished, this will be replaced by the actual file name.The loop keeps repeating as long there's a .crdownload file and stop, once this file no longer exists.By then, the download has finished and we can close the browser. Start the browser, go to the page which contains the downloadable fileand initiate the download Changelog2024-04-18 - Properly escape Windows paths Start the browser anduse the capabilitiesJSON providedby the flow variableNavigate to download page(here using “Palladian”on NodePit)Click thedownload linkNode 12Node 13Node 15Node 16List the filesin the temporary download directoryNode 18Node 19Node 20Wait a bitbefore repeatingiterationNode 22List the downloaded file --proceed as desired,e.g. move to desired destination, etc. Start WebDriver Navigate Click (deprecated) Create Temp Folder Path to String(Variable) URL to FilePath (Variable) String Manipulation(Variable) List Files/Folders Generic Loop Start(deprecated) Extract TableDimension Variable ConditionLoop End (deprecated) Wait Quit WebDriver List Files/Folders Build “Capabilities” JSON for the Start WebDriver node.It'll use a temporary directoy for the file download instead of hard-codingit into the JSON editor. Thus the workflow remains portable acrossdifferent environments and operating systems. The download has started now. But did it already finish?To check if the file has been completely downloaded, run a loop which will continuously check, if thedownload is complete. While the download is running, there's a temporary file which endswith .crdownload -- when it's finished, this will be replaced by the actual file name.The loop keeps repeating as long there's a .crdownload file and stop, once this file no longer exists.By then, the download has finished and we can close the browser. Start the browser, go to the page which contains the downloadable fileand initiate the download Changelog2024-04-18 - Properly escape Windows paths Start the browser anduse the capabilitiesJSON providedby the flow variableNavigate to download page(here using “Palladian”on NodePit)Click thedownload linkNode 12Node 13Node 15Node 16List the filesin the temporary download directoryNode 18Node 19Node 20Wait a bitbefore repeatingiterationNode 22List the downloaded file --proceed as desired,e.g. move to desired destination, etc. Start WebDriver Navigate Click (deprecated) Create Temp Folder Path to String(Variable) URL to FilePath (Variable) String Manipulation(Variable) List Files/Folders Generic Loop Start(deprecated) Extract TableDimension Variable ConditionLoop End (deprecated) Wait Quit WebDriver List Files/Folders

Nodes

Extensions

Links