3 ms·
>One thing I learned and wanted to warn about here is that Chrome headless currently doesn't support file downloads [1]. Not true. At least with C# You can use
by vadansky 9y ago
>One thing I learned and wanted to warn about here is that Chrome headless currently doesn't support file downloads [1].
Not true. At least with C# You can use
var client = new WebClient();
client.Headers[HttpRequestHeader.Cookie] = cookieString(driver);
client.DownloadFile(reportURL, savePath + fileName + ".xlsx");
Along with:
string cookieString(IWebDriver driver)
{
var cookies = driver.Manage().Cookies.AllCookies;
return string.Join("; ", cookies.Select(c => string.Format("{0}={1}", c.Name, c.Value)));
}
Edit: Just wanted to emphasize that this ensures all the steps you did to login won't be lost since you're using the logged in cookie.
The idea is to use Selenium to get the download url and then use a regular download method using the selenium cookie.
- thibaut_barrere 9y agoYes - I could have done that on other cases, but not in the specific case I tracked, where I don't know the report URL at all, nor I can construct it (it's generated by some enterprise app / javascript code). I think the bug report I mentioned relates to that. (otherwise you could use pretty much whatever you want to download the file, indeed).