Skip to content

Instantly share code, notes, and snippets.

@Bahm
Created December 23, 2016 05:59
Show Gist options
  • Save Bahm/a7c2485c144cb23154cda445e918d1f7 to your computer and use it in GitHub Desktop.
Save Bahm/a7c2485c144cb23154cda445e918d1f7 to your computer and use it in GitHub Desktop.
waitForElmWithTextToExist and getElmWithText
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