Wait for API call to finish
archieherbias opened this issue · 2 comments
archieherbias commented
I am accessing a webpage that has an API call when it's mounted. What I want is that I want to wait after the API call has finished/responded then create a PDF after that.
What should I do to wait for the page to get updated? The webpage is built on Reactjs.
My code is something like this.
const horseman = new Horseman()
horseman
.open('http://something/id')
.waitFor(function waitForValue(selector, initial) {
return $(selector).text() !== initial
}, '#id', '0.00', true)
.pdf('name.pdf', {
format: 'A4',
orientation: 'portrait',
margin: '0in'
})
.close()
awlayton commented
I am not familiar with React, so I do not know how you can go about determining when the page is "ready" for you.
I image you will need to find something specific to the particular page and how it changes. Using waitFor
like you are is probably on the right track.
archieherbias commented
Thanks for your response @awlayton but I switched to using nightmare and it seems it has tools for react as well.