Skip to main content

TimeoutError

每当某些操作由于超时而终止时,都会触发 TimeoutError,例如 locator.waitFor([options])browserType.launch([options])

const playwright = require('playwright');

(async () => {
const browser = await playwright.chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
try {
await page.locator("text=Foo").click({
timeout: 100,
})
} catch (error) {
if (error instanceof playwright.errors.TimeoutError)
console.log("Timeout!")
}
await browser.close();
})();