Skip to main content

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 playwright.APIRequest

公开可用于 Web API 测试的 API。

¥Exposes API that can be used for the Web API testing.

用法

¥Usage

Playwright.APIRequest

类型

¥Type


Chromium

Added before v1.9 playwright.Chromium

该对象可用于启动或连接到 Chromium,返回 Browser 的实例。

¥This object can be used to launch or connect to Chromium, returning instances of Browser.

用法

¥Usage

Playwright.Chromium

类型

¥Type


设备

¥Devices

Added before v1.9 playwright.Devices

返回与 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...
}
}

用法

¥Usage

Playwright.Devices

类型

¥Type


火狐浏览器

¥Firefox

Added before v1.9 playwright.Firefox

该对象可用于启动或连接到 Firefox,返回 Browser 的实例。

¥This object can be used to launch or connect to Firefox, returning instances of Browser.

用法

¥Usage

Playwright.Firefox

类型

¥Type


Selectors

Added before v1.9 playwright.Selectors

选择器可用于安装自定义选择器引擎。请参阅 extensibility 了解更多信息。

¥Selectors can be used to install custom selector engines. See extensibility for more information.

用法

¥Usage

Playwright.Selectors

类型

¥Type


Webkit

Added before v1.9 playwright.Webkit

该对象可用于启动或连接到 WebKit,返回 Browser 的实例。

¥This object can be used to launch or connect to WebKit, returning instances of Browser.

用法

¥Usage

Playwright.Webkit

类型

¥Type