Skip to main content

TimeoutError

每当某些操作由于超时而终止时,就会触发 TimeoutError ,例如 Locator.waitFor()BrowserType.launch()

¥TimeoutError is emitted whenever certain operations are terminated due to timeout, e.g. Locator.waitFor() or BrowserType.launch().

package org.example;

import com.microsoft.playwright.*;

public class TimeoutErrorExample {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.firefox().launch();
BrowserContext context = browser.newContext();
Page page = context.newPage();
try {
page.locator("text=Example").click(new Locator.ClickOptions().setTimeout(100));
} catch (TimeoutError e) {
System.out.println("Timeout!");
}
}
}
}