Created
December 23, 2016 05:59
-
-
Save Bahm/a7c2485c144cb23154cda445e918d1f7 to your computer and use it in GitHub Desktop.
waitForElmWithTextToExist and getElmWithText
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
function getElmWithText(selector, elmInnerText){ | |
var elms = document.querySelectorAll(selector); | |
for(var i = 0; i < elms.length; i++) | |
if (elms[i].innerText !== undefined && | |
elms[i].innerText.includes(elmInnerText)) | |
break; | |
return elms[i]; | |
} | |
function waitForElmWithTextToExist(selector, elmInnerText, thenAction){ | |
var elm = getElmWithText(selector, elmInnerText); | |
if(elm !== undefined){ | |
thenAction(elm); | |
}else{ | |
setTimeout(waitForElmWithTextToExist.bind(this, selector, elmInnerText, thenAction), 100); | |
} | |
} | |
waitForElmWithTextToExist('button', 'Create public gist', function(btn){ | |
btn.click(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment