Skip to main content
Original link is dead now, so I've added a link to web archive version and also included the code in the answer.
Source Link

This blog post (Archived version) describes a straight forward way of invoking another library to download the file (so not through the browser) whilst maintaining selenium's session with the site - so it works on password-protected files, etc.

Here's the code from the blog post:

using System.Net;
void downloadFile(IWebDriver driver, string url, string localPath)
{
    var client = new WebClient();
    client.Headers[HttpRequestHeader.Cookie] = cookieString(driver);
    client.DownloadFile(url, localPath);
}
string cookieString(IWebDriver driver)
{
    var cookies = driver.Manage().Cookies.AllCookies;
        return string.Join("; ", cookies.Select(c => string.Format("{0}={1}", c.Name, c.Value)));
}

This blog post describes a straight forward way of invoking another library to download the file (so not through the browser) whilst maintaining selenium's session with the site - so it works on password-protected files, etc.

This blog post (Archived version) describes a straight forward way of invoking another library to download the file (so not through the browser) whilst maintaining selenium's session with the site - so it works on password-protected files, etc.

Here's the code from the blog post:

using System.Net;
void downloadFile(IWebDriver driver, string url, string localPath)
{
    var client = new WebClient();
    client.Headers[HttpRequestHeader.Cookie] = cookieString(driver);
    client.DownloadFile(url, localPath);
}
string cookieString(IWebDriver driver)
{
    var cookies = driver.Manage().Cookies.AllCookies;
        return string.Join("; ", cookies.Select(c => string.Format("{0}={1}", c.Name, c.Value)));
}
Source Link

This blog post describes a straight forward way of invoking another library to download the file (so not through the browser) whilst maintaining selenium's session with the site - so it works on password-protected files, etc.