I\'ve been running the following code in order to download a csv file from the website http://niftyindices.com/resources/holiday-calendar:
I found a way to wait for browser capability to download a file. The idea is to wait for response with predicate. In my case URL ends with '/data'.
I just didn't like to load file contents into buffer.
await page._client.send('Page.setDownloadBehavior', {
behavior: 'allow',
downloadPath: download_path,
});
await frame.focus(report_download_selector);
await Promise.all([
page.waitForResponse(r => r.url().endsWith('/data')),
page.keyboard.press('Enter'),
]);