跳至主要内容

超时错误

  • 扩展: [错误]

当某些操作由于超时而终止时,例如 Locator.WaitForAsync()BrowserType.LaunchAsync(),会发出 TimeoutError。

using Microsoft.Playwright;

using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
try
{
await page.ClickAsync("text=Example", new() { Timeout = 100 });
}
catch (TimeoutException)
{
Console.WriteLine("Timeout!");
}