Created
October 4, 2015 11:24
-
-
Save avuori/15373fa9991f2d87a2d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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