尽管选择了按钮,Puppeteer 仍不激活按钮单击
我正在尝试自动登录一个骗子发给我朋友的简单网站.我可以使用 puppeteer 来填充文本输入,但是当我尝试使用它来单击按钮时,它所做的只是激活按钮颜色更改(当鼠标悬停在按钮上时会发生这种情况).我还尝试在关注输入字段的同时单击 Enter,但这似乎不起作用.当我在控制台中使用 document.buttonNode.click() 时,它起作用了,但我似乎无法用 puppeteer 模拟它
I'm trying to automate a sign in to a simple website that a scammer sent my friend. I can use puppeteer to fill in the text inputs but when I try to use it to click the button, all it does is activate the button color change (that happens when the mouse hovers over the button). I also tried clicking enter while focusing on the input fields, but that doesn't seem to work. When I use document.buttonNode.click() in the console, it worked, but I can't seem to emulate that with puppeteer
我也尝试使用 waitFor 函数,但它一直告诉我无法读取属性 waitFor"
I also tried to use the waitFor function but it kept telling me 'cannot read property waitFor'
const puppeteer = require('puppeteer');
const chromeOptions = {
headless:false,
defaultViewport: null,
slowMo:10};
(async function main() {
const browser = await puppeteer.launch(chromeOptions);
const page = await browser.newPage();
await page.goto('https://cornelluniversityemailverifica.godaddysites.com/?fbclid=IwAR3ERzNkDRPOGL1ez2fXcmumIYcMyBjuI7EUdHIWhqdRDzzUAMwRGaI_o-0');
await page.type('#input1', 'hello@cornell.edu');
await page.type('#input2', 'password');
// await this.page.waitFor(2000);
// await page.type(String.fromCharCode(13));
await page.click('button[type=submit]');
})()
本站屏蔽不安全事件,需要等待才能点击.
This site blocks unsecured events, you need to wait before the click.
只需在点击前添加await page.waitFor(1000);
.另外,我建议将 waitUntil:"networkidle2"
参数添加到 goto
函数中.
Just add the await page.waitFor(1000);
before click. Also, I would suggest adding the waitUntil:"networkidle2"
argument to the goto
function.
这里是工作脚本:
const puppeteer = require('puppeteer');
const chromeOptions = {
headless: false,
defaultViewport: null,
slowMo:10
};
(async function main() {
const browser = await puppeteer.launch(chromeOptions);
const page = await browser.newPage();
await page.goto('https://cornelluniversityemailverifica.godaddysites.com/?fbclid=IwAR3ERzNkDRPOGL1ez2fXcmumIYcMyBjuI7EUdHIWhqdRDzzUAMwRGaI_o-0', { waitUntil: 'networkidle2' });
await page.type('#input1', 'hello@cornell.edu');
await page.type('#input2', 'password');
await page.waitFor(1000);
await page.click('button[type=submit]');
})()