2

I came across a website which I was only able to enter a password in the security control that popped up. How to solve this problem using Puppeteer?

Below is my code:

const puppeteer = require('puppeteer');

const url = 'xxxx';

async function insertPwd() {
  const browser = await puppeteer.launch({
    ignoreHTTPSErrors: true,
    args: ['--ignore-certificate-errors', '--no-sandbox'],
    headless: false,
  });
  let page = await browser.newPage();

  await page.goto(url, { waitUntil: 'load' });

  const selector = '#SIPBox1';
  const input_value = 'abcdefg';

  await page.waitForSelector(selector, { timeout: 5000 });

  const input = await page.$(selector);
  await input.click();

  await page.focus(selector);
  await page.keyboard.type(input_value);
}

insertPwd();
ggorlen
  • 44,755
  • 7
  • 76
  • 106
homerqq
  • 21
  • 2

1 Answers1

-1

To enter a value in the text box that appears in the hidden block. You first need to call this block with a mouse click

const [xpathElement] = await page.$x(XPATH);
await xpathElement.click();

or

await page.mouse.click(X, Y, { button: 'left' })
gud3
  • 555
  • 3
  • 10
  • Actually I have clicked and there is no hidden form here – homerqq May 27 '22 at 01:37
  • In addition,I have set : `headless=false` , I can see the popup keyboard, but it doesn't work when using `page.type(selector, input_value); ` and `page.keyboard.type(input_value)` . I have to use the mouse to click on the keyboard that pops up – homerqq May 27 '22 at 01:47