如何使用 puppeteer 转到网页然后按 Control P 打印页面?
how to use puppeteer to goto web page then press Control P to print the page?
如何在 puppeteer 自动化的网页上按 control + P?
此代码加载网页。但是使用 await page.keyboard.down('Control')
按 Control 键没有效果。
(async () =>
{
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(`https://google.com`);
await page.waitForSelector('input');
await page.focus("input");
// this works
await page.keyboard.down('Shift');
await page.keyboard.press('KeyP');
await page.keyboard.up('Shift');
// this has no effect.
await page.keyboard.down('Control');
await page.keyboard.press('KeyP');
await page.keyboard.up('Control');
})();
我想做的是导航到 PDF 文件。让浏览器打开 PDF。然后按 Control P 并将打印对话框自动化到代码选择要打印到的打印机并按 Enter 键的程度。
运行 kiosk
模式下的 puppeteer 可以自动响应 window.print( )
对话框。
const puppeteer = require('puppeteer');
(async () =>
{
const browser = await puppeteer.launch(
{
headless: false,
"args": [ "--kiosk-printing" ]
});
const page = await browser.newPage();
await page.goto(`file:///C:/Users/srich/Downloads/packing-list.pdf`);
await page.evaluate(() => { window.print(); });
await page.waitForTimeout(2000) ;
await browser.close( ) ;
})();
如何在 puppeteer 自动化的网页上按 control + P?
此代码加载网页。但是使用 await page.keyboard.down('Control')
按 Control 键没有效果。
(async () =>
{
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(`https://google.com`);
await page.waitForSelector('input');
await page.focus("input");
// this works
await page.keyboard.down('Shift');
await page.keyboard.press('KeyP');
await page.keyboard.up('Shift');
// this has no effect.
await page.keyboard.down('Control');
await page.keyboard.press('KeyP');
await page.keyboard.up('Control');
})();
我想做的是导航到 PDF 文件。让浏览器打开 PDF。然后按 Control P 并将打印对话框自动化到代码选择要打印到的打印机并按 Enter 键的程度。
运行 kiosk
模式下的 puppeteer 可以自动响应 window.print( )
对话框。
const puppeteer = require('puppeteer');
(async () =>
{
const browser = await puppeteer.launch(
{
headless: false,
"args": [ "--kiosk-printing" ]
});
const page = await browser.newPage();
await page.goto(`file:///C:/Users/srich/Downloads/packing-list.pdf`);
await page.evaluate(() => { window.print(); });
await page.waitForTimeout(2000) ;
await browser.close( ) ;
})();