.document.injectScript() Suggest edits
Utility command to load an external script into the page specified by url.
Usage
.document.injectScript(scriptUrl, [callback])
.document.injectScript(scriptUrl, id, [callback])
Example
module.exports = {
'inject external script': function (browser) {
browser.document.injectScript('<script-url>', function () {
console.log('script injected successfully');
});
},
'inject external script using ES6 async/await': async function (browser) {
await browser.document.injectScript('<script-url>', 'injected-script');
}
};
Parameters
Name | Type | description |
---|---|---|
scriptUrl |
string | The script file url |
id Optional |
string | DOM element id to be set on the script tag. |
callback Optional |
function | Optional callback function to be called when the command finishes. |
Returns
Type | description |
---|---|
HTMLScriptElement | The newly created script tag. |