As part of the company product, User has to add a bookmarklet to the browser (a bookmark button that executes a JavaScript code instead of opening a URL).The source code of the bookmarklet is as follows:
javascript: (function () {
var d = document;
var script = d.createElement('scr'+'ipt');
script.src = 'https://<Company_URL>/Bookmarklet/ScriptContent?scriptFile=bm-script.js&rnd=' + Math.floor(Math.random() * 99999);
if (typeof script.onload === 'object') {
script.onload = function () {
doGeneralScript();
};
}
else {
script.onreadystatechange = function() {
if (this.readyState == 'complete' || this.readyState == 'loaded') {
doGeneralScript();
}
};
}
d.getElementsByTagName('head')[0].appendChild(script);
}());
The code basically opens a frame popup with some controls on it and the next step for the User is to click on one of the controls. Meantime, the Selenium IDE is unable to make a click on the button located outside the common area, so there are two ways of executing the script associated with the bookmarklet with the Selenium IDE:
- Create a one-liner script and make "open" statement. It works perfectly for the Firefox browser version 11.0 but causes non-fatal failure on Firefox 23.0.When on Firefox 23.0, the Selenium script makes pause and waits for the window to appear ignoring the frame popup. Eventually scripts resumes after throwing error.
- Write a custom user extension that will execute the script upon request
I tried to add the following three extensions to the Selenium Core extensions (user-extensions.js)
Selenium.prototype.doMbProduction = function()
{
var d = document;
var script = d.createElement('scr' + 'ipt');
script.src = 'https://<Company_URL>/Bookmarklet/ScriptContent?scriptFile=bm-script.js&rnd=' + Math.floor(Math.random() * 99999);
if (typeof script.onload === 'object') {
script.onload = this.doRunGeneralScript();
} else {
script.onreadystatechange = this.doPerformLoad();
}
d.getElementByTagName('head')[0].appendChild(script);
}
Selenium.prototype.doRunGeneralScript = function(){
script.doGeneralScript();
}
Selenium.prototype.doPerformLoad = function()
{
if (this.readyState == 'complete' || this.readyState == 'loaded') {
this.doRunGeneralScript();
}
}
But that won't work. Upon executing command mbProduction, the script throws fatal error
[error] Unexpected Exception: ReferenceError: script is not defined. fileName -> chrome://selenium-ide/content/tools.js -> file:///C:/Users/3pf/Downloads/sideflow1.js?1376849717650, lineNumber -> 124
the line 124 in my cutom user-extensions is script.doGeneralScript();
Can anybody help me find out what I am doing wrong, please? Any helpful suggestions are greatly appreciated.