1
votes

When I use puppeteer js web crawler, in waitForSelector handler I can use console.log without trouble:

page
  .waitForSelector('input[value=update]')
  .then(() => {
    console.log('this is');
    console.log('it');
  });

But I have an error when I want to interact with DOM:

page
  .waitForSelector('input[value=update]')
  .then(() => {
    const inputValidate = await page.$('input[value=update]');
  });

This code triggers this error:

const inputValidate = await page.$('input[value=update]'); ^^^^

SyntaxError: Unexpected identifier at createScript (vm.js:74:10) at Object.runInThisContext (vm.js:116:10) at Module._compile (module.js:537:28) at Object.Module._extensions..js (module.js:584:10) at Module.load (module.js:507:32) at tryModuleLoad (module.js:470:12) at Function.Module._load (module.js:462:3) at Function.Module.runMain (module.js:609:10) at startup (bootstrap_node.js:158:16) at bootstrap_node.js:598:3

Do you know how to intercat with DOM in a waitForSelector handler without trigger an error?

1
Might be a bug in puppeteer; try their forum/site.wOxxOm
You're missing async in .then(() => (...). It should be .then(async () => (...). I don't know if this will resolve your error though.tomahaug
@tomahaug yes it is! thank you!Vivien Pipo

1 Answers

1
votes
await page
  .waitForSelector('input[value=update]')
  .then(async() => {
    const inputValidate = await page.$('input[value=update]');
  });