跳至主要内容

TimeoutError

当某些操作由于超时而终止时,例如 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()