Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Click "OK" or "Cancel" button on Select a certificate to authenticate pop up in Playwright

I'm getting a "Select a certificate to authenticate" pop up window when I launch application, I tried keyboard event like pressing Enter Key to select pop up, but it's not working. is there any way to select OK button ?

const playwright = require('playwright');

browser = await playwright['chromium'].launch({ headless: false, args: ['--start-maximized', '--ignore-certificate-errors'] })
        const context = await browser.newContext({ viewport: null });
        const page = await context.newPage();
        await page.goto(domain);
        await page.waitForTimeout(6000)
        await page.keyboard.press('Enter');

enter image description here

like image 553
Sujith Avatar asked Oct 25 '25 01:10

Sujith


1 Answers

In Playwright version 1.46, support for TLS Client Certificates was added.

Here's an example using PEM format:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    clientCertificates: [{
      origin: 'https://example.com',
      certPath: './cert.pem',
      keyPath: './key.pem',
      passphrase: 'mysecretpassword',
    }],
  },
});

And here's an example using PFX format:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    clientCertificates: [{
      origin: 'https://example.com',
      pfxPath: './cert.pfx',
      passphrase: 'mysecretpassword',
    }],
  },
});
like image 105
Max Schmitt Avatar answered Oct 26 '25 16:10

Max Schmitt