Playwright
Playwright 模块提供了一种启动浏览器实例的方法。以下是使用 Playwright 进行自动化操作的典型示例:
🌐 Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright to drive automation:
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...
}
}
属性
🌐 Properties
APIRequest
Added in: v1.16公开可用于 Web API 测试的 API。
🌐 Exposes API that can be used for the Web API testing.
用法
Playwright.APIRequest
类型
Chromium
Added before v1.9此对象可用于启动或连接到 Chromium,并返回 Browser 实例。
🌐 This object can be used to launch or connect to Chromium, returning instances of Browser.
用法
Playwright.Chromium
类型
Devices
Added before v1.9返回一个设备字典,可与 Browser.NewContextAsync() 或 Browser.NewPageAsync() 一起使用。
🌐 Returns a dictionary of devices to be used with Browser.NewContextAsync() or 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 实例。
🌐 This object can be used to launch or connect to Firefox, returning instances of Browser.
用法
Playwright.Firefox
类型
Selectors
Added before v1.9选择器可用于安装自定义选择器引擎。有关更多信息,请参阅可扩展性。
🌐 Selectors can be used to install custom selector engines. See extensibility for more information.
用法
Playwright.Selectors
类型
Webkit
Added before v1.9此对象可用于启动或连接到 WebKit,并返回 Browser 的实例。
🌐 This object can be used to launch or connect to WebKit, returning instances of Browser.
用法
Playwright.Webkit
类型