Skip to content

Instantly share code, notes, and snippets.

@avuori
Created October 4, 2015 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avuori/15373fa9991f2d87a2d7 to your computer and use it in GitHub Desktop.
Save avuori/15373fa9991f2d87a2d7 to your computer and use it in GitHub Desktop.
if (!GLOBALS.poll_time) {
var poll_timeout_seconds = 3;
} else {
var poll_timeout_seconds = GLOBALS.poll_time;
}
var element = "iframe.locator";
var element_text = "Text to check";
var poll_frequency_ms = 500;
var counter = 0;
var max_loops = Math.round(poll_timeout_seconds * 1000 / poll_frequency_ms);
var checkIframeTextPresent = function (locator, text) {
if ($(locator).length == 0) return false;
return $(locator)[0].contentWindow.document.body.textContent.indexOf(text) !== -1;
};
var fn = function waitLoop() {
if (checkIframeTextPresent(element, element_text)) {
callback(true);
} else {
if (counter == max_loops) {
return callback("Couldn't find text '"+element_text+"' inside "+element+" in "+poll_timeout_seconds+"s");
//return callback(true);
}
counter++;
setTimeout(waitLoop, 1000);
}
}
fn();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment