Imacros / jQuery TypeError:无法访问死对象,第816行(错误代码:-991)

时间:2016-03-22 08:34:44

标签: javascript jquery imacros

我正在尝试编写一个使用jQuery的iMacros脚本,但似乎如果我刷新页面我得到了

TypeError: can't access dead object, line 816 (Error code: -991)

这是我目前的代码:

//Macros
refreshPage = "CODE:";
refreshPage += "SET !TIMEOUT_PAGE 30" + "\n";
refreshPage += "SET !ERRORIGNORE YES" + "\n";
refreshPage += "SET !TIMEOUT_STEP 2" + "\n";
refreshPage += "URL GOTO=somewebsite.com" + "\n";


    //Go to website
    iimPlay(refreshPage);

    //Main Code
    //Iclude jQuery
    function loadScriptFromURL(url) {
       var request = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Components.interfaces.nsIXMLHttpRequest),
       async = false;
       request.open('GET', url, async);
       request.send();
       if (request.status !== 200) {
          var message = 'an error occurred while loading script at url: ' + url + ', status: ' + request.status;
          iimDisplay(message);
          return false;
       }
       eval(request.response);
       return true;
    }
    loadScriptFromURL('https://www.dropbox.com/s/47cj0fqxnsijm2n/jquery-2.2.2.min.js?raw=1');
    $ = window.$,
       JQuery = window.JQuery;

    // Get List
    var jscList = [];
    var llcList = []; // not in use
    var companiesList = $('#companieshomelist').children();
    if (companiesList[0].innerText.match(/S.A./gi)) {
       for (var i = 1, j = companiesList.length; i < j; i++) {
          if (companiesList[i].innerText.match(/L.L.C/gi)) {
             break;
          } else {
             jscList.push(companiesList[i].innerText.split('\n')[0])
          }
       }
    }

    for (var i = 0, j = 1; i < j;i++) {
    iimPlay(refreshPage);
     foo() // script still works, foo can be anything js code/iMacros code and it works.
    companiesList[i+1].click(); // script throws dead object error, seems to happen if I try to use ANY jQuery code after page is refreshed 

    }

我想也许jquery需要再次加载所以我尝试移动它,复制它,甚至将它包含在一个名为refresh的函数中,其中包含刷新宏,因此它在页面刷新后立即加载但结果一切都是一样的。你可以通过代码告诉jQuery相当新的,所以我不知道如何解决这个问题,甚至问题是什么。

我可以选择使用/加载jQuery与Mozilla的任何其他方法。

FF / Mozilla 45.0.1 // iMacros 8.9.6 // Windows 7的// jQuery 2.2.2.min.js //

2 个答案:

答案 0 :(得分:1)

作为一种可能的解决方案,我只是重写了您的脚本,以便它可以使用已经加载到网页上的jQuery库。

//Macros
refreshPage = "CODE:";
refreshPage += "SET !TIMEOUT_PAGE 30" + "\n";
refreshPage += "SET !ERRORIGNORE YES" + "\n";
refreshPage += "SET !TIMEOUT_STEP 2" + "\n";
refreshPage += "URL GOTO=somewebsite.com" + "\n";

//Go to website
iimPlay(refreshPage);

// Get List
function getList() {
    var jscList = [];
    var llcList = []; /* not in use */
    var companiesList = $('#companieshomelist').children();
    if (companiesList[0].innerText.match(/S.A./gi)) {
       for (var i = 1, j = companiesList.length; i < j; i++) {
          if (companiesList[i].innerText.match(/L.L.C/gi)) {
             break;
          } else {
             jscList.push(companiesList[i].innerText.split('\n')[0])
          }
       }
    }
}

window.location.href = "javascript:{" + getList.toString() + "getList(); undefined;}";
iimPlayCode("WAIT SECONDS=0.3");

for (var i = 0, j = 1; i < j;i++) {
    iimPlay(refreshPage);
    foo() // script still works, foo can be anything js code/iMacros code and it works.
    window.location.href = "javascript:{" + getList.toString() + "getList(); companiesList[" + (i + 1) + "].click(); undefined;}";
    iimPlayCode("WAIT SECONDS=0.3");
}

答案 1 :(得分:1)

我没有注意到完整的错误,似乎我有两个问题,就像shugar在评论中指出的那样。刷新后必须再次加载jQuery,并且由于某种原因必须再次定义companiesList。

function loadJQ() {
    function loadScriptFromURL(url) {
        var request = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Components.interfaces.nsIXMLHttpRequest),
        async = false;
        request.open('GET', url, async);
        request.send();
        if (request.status !== 200) {
            var message = 'an error occurred while loading script at url: ' + url + ', status: ' + request.status;
            iimDisplay(message);
            return false;
        }
        eval(request.response);
        return true;
    }
    loadScriptFromURL('https://www.dropbox.com/s/47cj0fqxnsijm2n/jquery-2.2.2.min.js?raw=1');
    $ = window.$,
    JQuery = window.JQuery;
}
loadJQ()    

var jscList = [];
var llcList = []; // not in use
var companiesList = $('#companieshomelist').children();
if (companiesList[0].innerText.match(/S.A./gi)) {
    for (var i = 1, j = companiesList.length; i < j; i++) {
        if (companiesList[i].innerText.match(/L.L.C/gi)) {
            break;
        } else {
            jscList.push(companiesList[i].innerText.split('\n')[0])
        }
    }
}

for (var i = 0;i < 1;i++) {
iimPlay(refresh)
loadJQ()
companiesList = $('#companieshomelist').children();
companiesList[i+1].click(); 

}