My solution (in C #) gets the URL of the download file and any cookie and makes a request using WebClient:
var testLink = seleniumDriver.FindElement(By.LinkText("Link to file"));
var pdfHref = testLink.GetAttribute("href");
var manage = seleniumDriver.Manage();
var cookies = manage.Cookies.AllCookies;
using (var wc = new WebClient())
{
foreach (var cookie in cookies)
{
var cookieText = cookie.Name + "=" + cookie.Value;
wc.Headers.Add(HttpRequestHeader.Cookie, cookieText);
}
var fileResult = wc.DownloadData(new Uri(pdfHref));
}
source
share