Playwright for .NET
[删除(380066935@qq.com或微信通知)]
更好的阅读体验请查看原文:https://github.com/microsoft/playwright-dotnet
Playwright for .NET 是 Playwright 的官方语言端口,该库使用单个 API 自动化 Chromium、Firefox 和 WebKit。 Playwright 旨在实现常绿、强大、可靠和快速的跨浏览器 Web 自动化。
Documentation
https://playwright.dev/dotnet/docs/intro
API Reference
https://playwright.dev/dotnet/docs/api/class-playwright
using System.Threading.Tasks;
using Microsoft.Playwright;
class Program
{
public static async Task Main()
{
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync(new() { Headless = false });
var page = await browser.NewPageAsync();
await page.GotoAsync("https://playwright.dev/dotnet");
await page.ScreenshotAsync(new() { Path = "screenshot.png" });
}
}
using Microsoft.Playwright;
using System.Threading.Tasks;
class DialogExample
{
public static async Task Run()
{
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
page.Dialog += async (_, dialog) =>
{
System.Console.WriteLine(dialog.Message);
await dialog.DismissAsync();
};
await page.EvaluateAsync("alert('1');");
}
}