【问题标题】:Puppeteer Error: Node is either not visible or not an HTMLElementPuppeteer 错误:节点不可见或不是 HTMLElement
【发布时间】:2020-06-05 00:38:04
【问题描述】:

我想点击并在本网站的密码输入栏输入:https://undefeated.com

不幸的是,以下代码可用于输入名字、姓氏、电子邮件,但在尝试访问密码字段时出现错误:

(node:17236) UnhandledPromiseRejectionWarning: Error: Node is either not visible or not an HTMLElement

如果您想尝试重现错误,这是代码:


const RandExp = require('randexp');
const puppeteer = require('puppeteer-extra')

const stuff = async (siteURL) => {
    let args;


  args = [
    '--no-sandbox',
    "--ignore-certificate-errors",
    "--proxy-server='direct://",
    "--proxy-bypass-list=*",
    "--disable-setuid-sandbox",
    '--disable-web-security'
  ]

    // # spawn browser
    browser = await puppeteer.launch({
        headless: false,
        args,
        ignoreHTTPSErrors: true,
        devtools: false,
        defaultViewport: null
    });

    page = await browser.newPage();
    (await browser.pages())[0].close();
    await page.setViewport({ width: 0, height: 0 })
    await page.setDefaultNavigationTimeout(0);

   page.goto("https://"+siteURL+'/account/register', { waitUntil: 'networkidle2' });

    const resp = await waitForNavigation(page);

    if (resp.status() == 200) {
        // # wait for a selector
        let isFirstName = await page.waitForSelector('#FirstName');
        if(isFirstName){
          var firstName = new RandExp('[A-Z]{1}[a-z]{2,10}').gen();
          await page.click('#FirstName', { visible: true });
          await page.type('#FirstName', firstName, { delay: 50 });
        }

        let isLastName = await page.waitForSelector('#LastName');
        if(isLastName){
          var lastName = new RandExp('[A-Z]{1}[a-z]{2,10}').gen();
          await page.click('#LastName', { visible: true });
          await page.type('#LastName', lastName, { delay: 50 });
        }

        let isEmail = await page.waitForSelector('#Email');
        if(isEmail){
          let email = new RandExp('[A-Z]{1}[a-z0-9]{10}@gmail[.]com').gen()
          console.log(email)
          await page.click('#Email', { visible: true });
          await page.type('#Email', email, { delay: 50 });
        }

        let isPassword = await page.waitForSelector('#CreatePassword');
        if(isPassword){
          var password = new RandExp('[A-Z]{1}[A-Za-z0-9]{6,13}[0-9]{1}').gen();
          console.log(password)
          await page.click('#CreatePassword', { visible: true })
          await page.type('#CreatePassword', password, { delay: 50 });
        }

        // let agree = await page.waitForSelector('#account-create-check', {timeout: 1000});
        // if(agree){
        //   await page.click('#account-create-check', { visible: true });
        // }


    }
  };

    const waitForNavigation = async (page)  => {
      const [resp] = await Promise.all([
          page.waitForNavigation({
              timeout: 0,
              waitUntil: ['networkidle2', 'load', 'domcontentloaded']
          })
      ]);

      return resp;
  }

stuff("undefeated.com");

有人能解释一下这个错误是什么意思,为什么我可以通过它?

感谢所有帮助:)

【问题讨论】:

    标签: javascript node.js http puppeteer chromium


    【解决方案1】:

    这似乎不对:

    await page.setViewport({ width: 0, height: 0 })
    

    您的视口应模仿真实浏览器的视口,因此请务必使用some plausible values 进行设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-12
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多