Zum Inhalt springen

Playwright

  • Microsoft.Playwright
PlaywrightInstaller.cs
public static class PlaywrightInstaller
{
public static void Install(string browser = "chromium")
{
var exitCode = Microsoft.Playwright.Program.Main(new[] { "install", "--with-deps", browser });
if (exitCode != 0) throw new Exception($"Playwright-Installation fehlgeschlagen. Exit-Code: {exitCode}");
}
}
Program.cs
PlaywrightInstaller.Install();
Example.cs
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
await page.GotoAsync("https://playwright.dev/dotnet");
await page.ScreenshotAsync(new()
{
Path = "screenshot.png"
});