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?
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()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With