Skip to main content

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

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

使用方式

Playwright.APIRequest

型別 (Type)


Chromium

Added before v1.9 playwright.Chromium

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

使用方式

Playwright.Chromium

型別 (Type)


Devices

Added before v1.9 playwright.Devices

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

型別 (Type)


Firefox

Added before v1.9 playwright.Firefox

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

使用方式

Playwright.Firefox

型別 (Type)


Selectors

Added before v1.9 playwright.Selectors

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

使用方式

Playwright.Selectors

型別 (Type)


Webkit

Added before v1.9 playwright.Webkit

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

使用方式

Playwright.Webkit

型別 (Type)