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...
}
}
属性
API请求
Added in: v1.16提供可用于Web API测试的API接口。
用法
Playwright.APIRequest
类型
Chromium
Added before v1.9该对象可用于启动或连接到Chromium,返回Browser的实例。
用法
Playwright.Chromium
类型
设备
Added before 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
Added before v1.9该对象可用于启动或连接到Firefox,返回Browser的实例。
用法
Playwright.Firefox
类型
选择器
Added before v1.9选择器可用于安装自定义选择器引擎。更多信息请参阅extensibility。
用法
Playwright.Selectors
类型
Webkit
Added before v1.9该对象可用于启动或连接到WebKit,返回Browser的实例。
用法
Playwright.Webkit
类型