“选择证书”对话框未在 puppeteer 中关闭

问题描述 投票:0回答:1

在我的 Puppeteer 脚本中,我想关闭一些交互后出现的对话框,如下所示

我尝试了不同的方法来关闭此对话框,但没有任何效果。

我分别尝试了以下方法,但没有任何效果。

 await page.keyboard.down('Enter');
  await page.keyboard.down(String.fromCharCode(13));
  await page.keyboard.type(String.fromCharCode(13));
  await page.keyboard.press(String.fromCharCode(13));   
   await page.keyboard.press('Enter');

page.on('dialog', async dialog => {
    await dialog.accept();
   });

以上均无效,如果可以通过其他代码关闭,您能帮我吗?或者如果是浏览器警报

实际代码:

const browser = await puppeteer.launch({
      headless: false,
      args: ['--lang="de-DE"']
    });
   const page = await browser.newPage();
   page.on('dialog', async dialog => {
    await dialog.accept();
   });
   await page.setExtraHTTPHeaders({
    'Accept-Language': 'de'
  });
   await page.goto(url, { waitUntil: 'networkidle2'});
  
   await page.click("#ID_secure18");
   await page.click("#btn_MethodNext");
// Tried all below ones:
  await page.keyboard.down('Enter');
  await page.keyboard.down(String.fromCharCode(13));
  await page.keyboard.type('Enter');
  await page.keyboard.type(String.fromCharCode(13));
  await page.keyboard.press(String.fromCharCode(13));
  await page.keyboard.press('Enter');
  await page.keyboard.up('Enter');
  await page.keyboard.up(String.fromCharCode(13));
  await page.waitForNavigation({waitUntil: 'networkidle2'});
  await browser.close();
javascript node.js puppeteer google-chrome-headless
1个回答
0
投票

Pode colocar o código aqui。 Estou com o mesmo Problema。 梅乌科迪戈:

await page.goto(process.env.CONECTIVIDADE_ENDPOINT);
const btnEmpregador = await page.waitForSelector("#btnEmpregador");
await btnEmpregador.click();
await page.keyboard.type('Enter');
© www.soinside.com 2019 - 2024. All rights reserved.