Wait for an AJAX load of content to complete
I am coming across from Nightmare, and am excited about the ability to branch & use promises with this project, so thanks for creating it.
I need to wait for an AJAX load of content in the page before I proceed with my script. In Nightmare, I would use the wait('selector') function, but I don't see that here.
Is there a way to wait until a node is available on the page please? Or is there another approach to waiting until an AJAX load completes?
Thanks!
I had seen that feature in Nightmare. I'll look into adding this.
Currently you could probably do something like...
ph.open('test.com')
.then(function () {
return new Promise(function (resolve, reject) {
var i = setInterval(function () {
ph.evaluate(function () {
var element = document.querySelector('#ajax');
return !!element;
}).then(function (present) {
if(present){
clearInterval(i);
resolve();
}
});
}, 100);
});
});
Untested but could do the trick. Obviously moving this into Phantasma would be a nicer solution
just notes for myself with what they do in Nightmare: https://github.com/segmentio/nightmare/blob/master/lib/actions.js#L338 https://github.com/segmentio/nightmare/blob/master/lib/index.js#L194