您可以使用 Puppeteer 在提示框的文本字段中输入内容吗?
Can you input into the text field of a prompt box using Puppeteer?
我正在尝试将字符输入对话框的提示框中,例如 this one. However, I can't seem to find any way of doing this. There are some useful methods that I found in the Puppeteer documentation,但是 none 这确实可以帮助我完成我正在尝试做的事情。我想知道是否有任何创造性的解决方法来实现这一目标。
您必须使用 dialog event. Once there, you can use dialog.accept 来设置文本。这将在您的示例中输入 "Stack Overflow":
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_prompt");
const frame = (await page.frames())[1];
page.on('dialog', dialog => {
dialog.accept("Stack Overflow!");
});
await frame.click("BUTTON")
browser.close();
我正在尝试将字符输入对话框的提示框中,例如 this one. However, I can't seem to find any way of doing this. There are some useful methods that I found in the Puppeteer documentation,但是 none 这确实可以帮助我完成我正在尝试做的事情。我想知道是否有任何创造性的解决方法来实现这一目标。
您必须使用 dialog event. Once there, you can use dialog.accept 来设置文本。这将在您的示例中输入 "Stack Overflow":
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_prompt");
const frame = (await page.frames())[1];
page.on('dialog', dialog => {
dialog.accept("Stack Overflow!");
});
await frame.click("BUTTON")
browser.close();