TimeoutError
当某些操作因超时而终止时,例如 Locator.waitFor() 或 BrowserType.launch(),会发出 TimeoutError。
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!");
}
}
}
}