zia*_*ali 2 javascript webautomation node.js puppeteer
我正在单击包含确认对话框但无法关闭的链接。
我尝试按“Enter”并使用 puppeteer 的方法关闭并接受对话框,但什么也没发生。
链接:
<a onclick="return confirm('Yes?');" id="link" href="google.com">
Run Code Online (Sandbox Code Playgroud)
我试过:
page.on('dialog', async dialog => {
console.log('here'); //does not pass
await dialog.accept();
//await dialog.dismiss();
});
Run Code Online (Sandbox Code Playgroud)
和
await page.keyboard.press('Enter');
await page.keyboard.press(String.fromCharCode(13));
Run Code Online (Sandbox Code Playgroud)
确保在单击链接之前开始收听dialog事件。像这样的东西:
page.on('dialog', async dialog => {
console.log('here');
await dialog.accept();
});
await page.click('a');
Run Code Online (Sandbox Code Playgroud)