I am facing an issue while automatically downloading a theme on Wordpress using PhantomJS. The problem arises because the page is not fully evaluated even after it appears to be done loading.
When trying to interact with elements on the page, such as clicking a button, they are not visible due to delayed database queries. This leads to essential components missing from the loaded page, as shown in the image below:
https://i.sstatic.net/QUQTR.png
The theme card fails to appear as expected, and instead, only a spinning loader is displayed. This spinner causes issues with any theme-related scripts.
Do you have any suggestions on how to resolve this issue? I have tried using setTimeout()
without success so far. Any help would be appreciated!
ADDITIONAL INFORMATION
All functions in my script run after a predefined interval set using the setInterval
method. While this works well for executing tasks sequentially, I am now looking for a way to dynamically adjust the interval time as functions are executed. See a snippet of the code below:
var steps = [
function() {
console.log('Going')
page.open('http://google.com')
//Requires minimal time
},
function() {
console.log('Searching')
page.evaluate(function() {
//Complex tasks that need more time
})
}]
//Setting the interval:
setInterval(executeRequestsStepByStep, 250)
function executeRequestsStepByStep(){
if (loading == false && steps[stepindex]) {
steps[stepindex]()
stepindex++
}
if (!steps[stepindex]) {
phantom.exit()
}
}
page.onLoadStarted = function() { loading = true }
page.onLoadFinished = function() { loading = false }
If you have any insights on how to achieve dynamic interval adjustment during script execution, please share your thoughts!