TimeoutError
- 继承自: Error
当某些操作由于超时而终止时,例如 locator.wait_for() 或 browser_type.launch(),就会发出 TimeoutError。
- 同步
- 异步
from playwright.sync_api import sync_playwright, TimeoutError as PlaywrightTimeoutError
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
try:
page.locator("text=Example").click(timeout=100)
except PlaywrightTimeoutError:
print("Timeout!")
browser.close()
import asyncio
from playwright.async_api import async_playwright, TimeoutError as PlaywrightTimeoutError, Playwright
async def run(playwright: Playwright):
browser = await playwright.chromium.launch()
page = await browser.new_page()
try:
await page.locator("text=Example").click(timeout=100)
except PlaywrightTimeoutError:
print("Timeout!")
await browser.close()
async def main():
async with async_playwright() as playwright:
await run(playwright)
asyncio.run(main())