Puppeteer does not activate button click, despite selecting button

折月煮酒 提交于 2021-01-25 07:00:24

问题


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

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]');
})()

回答1:


This site blocks unsecured events, you need to wait before the click.

Just add the await page.waitFor(1000); before click. Also, I would suggest adding the waitUntil:"networkidle2" argument to the goto function.

So here is the working script:

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]');
})()


来源:https://stackoverflow.com/questions/57281628/puppeteer-does-not-activate-button-click-despite-selecting-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!