添加浏览器认证

78 阅读1分钟
try (Playwright playwright = Playwright.create()) {
    Browser browser = playwright.chromium().launch();
    Page page = browser.newPage();

    // Step 1: Open the browser certificate link
    String certificateLink = "https://example.com/aaa"; // Replace with your certificate link
    page.navigate(certificateLink);
    page.waitForLoadState();

    // Step 2: Click on the "Trust" button
    ElementHandle trustButton = page.waitForSelector("button#trustButton"); // Replace with the actual selector for the "Trust" button
    trustButton.click();
    page.waitForLoadState();

    // Step 3: Open your page
    String testPageUrl = "https://test.com"; // Replace with your test page URL
    page.navigate(testPageUrl);
    page.waitForLoadState();

    // Continue with your testing or perform any further steps

    browser.close();
} catch (PlaywrightException e) {
    e.printStackTrace();
}