2017-07-19 49 views
0

使用Selenium IDE記錄Web操作時,但IDE正在停止JavaScript,並出現錯誤消息「太多遞歸」。Selenium IDE正在停止javascript

硒IDE 2.9.1.1

瀏覽器:Firefox 54.0.1

我寫了一個簡單的JavaScript警報進行測試,它也停止硒。

<html> 
<head> 
    <script> 
     function hello(){ 
      alert("Hello\nHow are you?"); 
     } 
    </script> 
</head> 
<body> 
    <input type="button" onclick="hello();" value="Say Hi" /> 
</body> 
</html> 

enter image description here

硒-IDE /內容/ recorder.js

Recorder.prototype.reattachWindowMethods = function() { 
    var window = this.getWrappedWindow(); 
    //this.log.debug("reattach"); 
    if (!this.windowMethods) { 
     this.originalOpen = window.open; 
    } 
    this.windowMethods = {}; 
    ['alert', 'confirm', 'prompt', 'open'].forEach(function(method) { 
      this.windowMethods[method] = window[method]; 
     }, this); 
    var self = this; 
    window.alert = function(alert) { 
     self.windowMethods['alert'].call(self.window, alert); 
     self.record('assertAlert', alert); 
    } 
} 
+1

顯示您的硒腳本 – Liam

+0

剛剛更新,該例外是來這裏'self.windowMethods [ '警報']調用(self.window,警告);' – Jotzuc

回答

0

這是因爲該函數調用實際上正在運行時通過硒自己的JavaScript覆蓋。 加入下面的Javascript代碼到selenium核心用戶擴展,重啓後可以修復這個問題。

//http://docs.seleniumhq.org/docs/08_user_extensions.jsp 
Selenium.prototype.doExecute = function(script) { 
    this.browserbot.getCurrentWindow().eval(script); 
}; 
Selenium.prototype.getExecute = function(script) { 
    return this.browserbot.getCurrentWindow().eval(script); 
}; 
Selenium.prototype.getJqMethod = function(selector, method) { 
    return this.getExecute('$("' + selector + '").' + method + '();'); 
}; 
Selenium.prototype.getJqText = function(selector) { 
    return this.getJqMethod(selector, "text"); 
}; 
Selenium.prototype.getJqHtml = function(selector) { 
    return this.getJqMethod(selector, "html"); 
}; 
Selenium.prototype.getJqVal = function(selector) { 
    return this.getJqMethod(selector, "val"); 
}; 
PageBot.prototype.locateElementByJq = function(selector, inDocument) { 
    // FF/Chrome/IE9+: defaultView, OldIE: parentWindow 
    return (inDocument.defaultView || inDocument.parentWindow) 
      .eval("jQuery('" + selector.replace(/'/g, "\\'") + "')[0];"); 
};