I'm trying to identify when a particular element is showed on the page. For example I want to write a script that tell me if in the page there is a banner like the follows:
the problem is that the banner is loaded when the DOM state changes ( s.addEventListener(document,"readystatechange",o) )
It is not visible on screenshot too.
How can I solve this? I tried using Waitfor by checking for an element with class "cc_banner-wrapper" but doesn't work. I'm trying also to start the page.evaluate after another one that waits until the DOM state change from loading to complete:
var status = "";
var trying = 0;
do {
if( status == "interactive" ) {
var start = Date.now();
while (Date.now() < start + 3000); // Wait 3 seconds
trying++;
}
var status = page.evaluate(function () {
return document.readyState;
});
console.log("\n\nDOM Status: "+status);
} while( status != "complete" && trying < 3 );
// Now the DOM status is "complete"
var response = page.evaluate(function() {
function check_banner() {
if( document.getElementsByClassName("cc_banner-wrapper").length > 0)
return 1;
else
return 0;
}
return check_banner();
});
// Response is always 0 - it never find .cc_banner-wrapper
Thanks