Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. if (!GLOBALS.poll_time) {
  2. var poll_timeout_seconds = 3;
  3. } else {
  4. var poll_timeout_seconds = GLOBALS.poll_time;
  5. }
  6.  
  7. var element = "iframe.locator";
  8. var element_text = "Text to check";
  9.  
  10. var poll_frequency_ms = 500;
  11. var counter = 0;
  12. var max_loops = Math.round(poll_timeout_seconds * 1000 / poll_frequency_ms);
  13.  
  14. var checkIframeTextPresent = function (locator, text) {
  15. if ($(locator).length == 0) return false;
  16. return $(locator)[0].contentWindow.document.body.textContent.indexOf(text) !== -1;
  17. };
  18.  
  19. var fn = function waitLoop() {
  20. if (checkIframeTextPresent(element, element_text)) {
  21. callback(true);
  22. } else {
  23. if (counter == max_loops) {
  24. return callback("Couldn't find text '"+element_text+"' inside "+element+" in "+poll_timeout_seconds+"s");
  25. //return callback(true);
  26. }
  27. counter++;
  28. setTimeout(waitLoop, 1000);
  29. }
  30. }
  31. fn();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement