import com.microsoft.playwright.*;
public class BrowserCertificateExample {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType browserType = playwright.chromium();
Browser browser = browserType.launch(new BrowserType.LaunchOptions().setHeadless(false));
BrowserContext context = browser.newContext();
Page page = context.newPage();
// Step 1: Navigate to the initial page (link aaa)
page.navigate("https://example.com/aaa");
page.waitForLoadState();
// Step 2: Click on a link or button that leads to the target page (link bbb)
page.click("a#target-link");
page.waitForLoadState();
// Step 3: Handle the browser certificate prompt
page.onCertificateError(event -> {
event.handle(true); // Bypass certificate error and continue
});
page.waitForNavigation(new Page.WaitForNavigationOptions().setUrl("https://example.com/bbb"));
// The browser certificate is trusted, continue with your actions on the target page
// Your code here - perform actions on the target page
// Close the page and context
page.close();
context.close();
}
}
}