Many of suggested that I just utilize the .onload
and fire a callback once the script is ready. That doesn't work for me. I'm writing a function and it expects an element immediately, not at a later time. Here's what I've got:
webdriver.By.sizzle = function(selector) {
driver.executeScript("if(typeof Sizzle==='undefined'){var s=document.createElement('script');s.type='text/javascript';s.src='https://raw.github.com/jquery/sizzle/master/src/sizzle.js';document.head.appendChild(s);}");
return new webdriver.By.js("return Sizzle('"+selector.replace(/"/g,'\\"')+"')[0]");
};
I want to inject Sizzle (if it's not already included) and then return an HtmlElement
. It can busy-wait if it needs to, but it has to return an HtmlElement.
All the answers here basically just said "don't do it", but I can't think of another way.
This is a selector for selenium web driver for JavaScript.
driver.executeScript
will take arguments. I wonder if I can pass in a webdriver.promise
and have it invoked when the script is loaded...? I don't know how to 'fufill' a promise.