Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chromeless - wait before executing instructions

I am using Chromeless to retrieve a piece of information on a website and load a corresponding file:

async function run() {
  const chromeless = new Chromeless()

      const screenshot = await chromeless
        .goto('http://www.website.com')
         title = await chromeless.inputValue('input[name="title"]')

         var fs = require('fs');
         var data = fs.readFileSync(title,"utf8");
         ...
    await chromeless.end()
}

but the file read instructions are executed immediately when I launch the script and do not wait for the web crawling to be finished.

In javascript I think I would need to use callback functions to prevent that but is there a better way to do this with Chromeless?

like image 440
Sulli Avatar asked Jan 12 '18 03:01

Sulli


1 Answers

You can try passing implicitWait: true to the Chromeless constructor. This value is false by default. Setting this to true will make Chromeless wait for elements to exist before executing commands.

In other words, var fs = require('fs'); shouldn't get executed until const title is assigned.

async function run() {
  const chromeless = new Chromeless({implicitWait: true})
  const screenshot = await chromeless.goto('http://www.website.com')
  const title = await chromeless.inputValue('input[name="title"]')

  var fs = require('fs');
  var data = fs.readFileSync(title,"utf8");
  ...
  await chromeless.end()
}
like image 114
grizzthedj Avatar answered Nov 16 '22 10:11

grizzthedj