Selenium 如何处理Puppeter以从打印对话框保存pdf?

Selenium 如何处理Puppeter以从打印对话框保存pdf?,selenium,automation,headless-browser,puppeteer,google-chrome-headless,Selenium,Automation,Headless Browser,Puppeteer,Google Chrome Headless,我有一个打印按钮,点击它,发送一些请求并打开打印对话框。现在,这不是直接来自URL,也不容易解码 打印对话框示例 是否有一种方法可以使用Puppeter将此文档保存为pdf 现行守则: const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.

我有一个打印按钮,点击它,发送一些请求并打开打印对话框。现在,这不是直接来自URL,也不容易解码

打印对话框示例

是否有一种方法可以使用Puppeter将此文档保存为pdf

现行守则:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setViewport({width: 1440, height: 2000});
  await page.goto(`https://www.southwest.com/air/check-in/review.html?confirmationNumber=${process.argv[2]}&passengerFirstName=${process.argv[3]}&passengerLastName=${process.argv[4]}`, {
    waitUntil: 'networkidle2'
  });
  [ confirmationNumber, checkinButtonText ] = [ await page.$eval('.confirmation-number--code', el => el.innerHTML), await page.$eval('.actionable_primary.actionable_large-button', el => el.innerHTML) ]
  console.log(checkinButtonText);
  console.log(confirmationNumber);
  await page.click('.actionable_primary.actionable_large-button');
  // The below line makes a click on the button
  await page.click('.air-check-in-boarding-pass-options .boarding-pass-options--button-email, .air-check-in-boarding-pass-options .boarding-pass-options--button-print, .air-check-in-boarding-pass-options .boarding-pass-options--button-text');
  await browser.close();

})();

这有一个.pdf api

用法示例:

await page.pdf({path: 'myTicket.pdf'});

请共享您的代码和结果示例。请检查更新的代码。我认为这对你没有帮助,除非你以前有西南航空公司的机票