Playwright.Net下载文件,使用WaitForDownloadAsync
Playwright = await Microsoft.Playwright.Playwright.CreateAsync();
var userDataDir = $"{Directory.GetCurrentDirectory()}\\UserData";
var context = await Playwright.Chromium.LaunchPersistentContextAsync(userDataDir,
new BrowserTypeLaunchPersistentContextOptions
{
Headless = false,
AcceptDownloads=true,
ExecutablePath = SystemConsts.ChromeExecutablePath,
ViewportSize = new ViewportSize()
{
Width = 1920,
Height = 1080
}
//Args = new List<string> { "--start-maximized" }
}
);
public static async Task DownAsync()
{
var waitForDownloadTask = Page.WaitForDownloadAsync();
await Page.ClickAsync("text=下载");
var download = await waitForDownloadTask;
await download.SaveAsAsync(download.SuggestedFilename);
}