Playwright
Playwright 模块提供了一种启动浏览器实例的方法。以下是使用 Playwright 驱动自动化的典型示例
using Microsoft.Playwright;
using System.Threading.Tasks;
class PlaywrightExample
{
public static async Task Main()
{
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
await page.GotoAsync("https://www.microsoft.com");
// other actions...
}
}
属性
APIRequest
新增于:v1.16公开了可用于 Web API 测试的 API。
用法
Playwright.APIRequest
类型
Chromium
新增于 v1.9 之前此对象可用于启动或连接到 Chromium,并返回 Browser 的实例。
用法
Playwright.Chromium
类型
设备
新增于 v1.9 之前返回一个设备字典,用于 Browser.NewContextAsync() 或 Browser.NewPageAsync()。
using Microsoft.Playwright;
using System.Threading.Tasks;
class PlaywrightExample
{
public static async Task Main()
{
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Webkit.LaunchAsync();
await using var context = await browser.NewContextAsync(playwright.Devices["iPhone 6"]);
var page = await context.NewPageAsync();
await page.GotoAsync("https://www.theverge.com");
// other actions...
}
}
用法
Playwright.Devices
类型
- IReadOnlyDictionary<string, [BrowserNewContextOptions]>
Firefox
新增于 v1.9 之前此对象可用于启动或连接到 Firefox,并返回 Browser 的实例。
用法
Playwright.Firefox
类型
选择器
新增于 v1.9 之前选择器可用于安装自定义选择器引擎。有关更多信息,请参阅 可扩展性。
用法
Playwright.Selectors
类型
Webkit
新增于 v1.9 之前此对象可用于启动或连接到 WebKit,并返回 Browser 的实例。
用法
Playwright.Webkit
类型