I want to set download behaviour of browser for testing needs
I had tried solution from this topic: puppeteer - how to set download location
var browser = await StartNewChromeAsync(); //starting new chrome without extensions
var pages = await browser.PagesAsync();
var firstPage = pages[0];
var cdp = await firstPage.Target.CreateCDPSessionAsync();
await cdp.SendAsync("Page.setDownloadBehavior", new
{
behavior = "allow",
downloadPath = Path.GetAbsolutePath("./testing_downloads")
});
await cdp.DetachAsync();
I expecting, that files will be downloaded in ./testing_downloads
, but it downloadings in default path.
What am i doing wrong?
//Set the options for download file through puppeteer
var options = new LaunchOptions
{
Headless = false,
ExecutablePath = "Path Of Browser to execute, example c://....edge.exe ", //
DefaultViewport = null,
Args = new[] { "--no-sandbox", "--start-maximized" },
};//Launch puppeteer for scrap the Document Data
using (var browser = await Puppeteer.LaunchAsync(options))
using (var page = await browser.NewPageAsync())
{
await page.Target.CreateCDPSessionAsync().Result.SendAsync("Page.setDownloadBehavior", new
{
behavior = "allow",
downloadPath = directoryToSave
}, false);
await page.AuthenticateAsync(new Credentials
{
Username = WindowsCredentials.Username,
Password = WindowsCredentials.Password
});
await page.GoToAsync("URL of file to download");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With