2017-07-19 8 views
0

Wenn Sie Selenium IDE verwenden, um die Webaktion aufzuzeichnen, aber die IDE stoppt das JavaScript und kommt die Fehlermeldung "zu viel Rekursion" heraus.Selenium IDE stoppt JavaScript

Selenium IDE 2.9.1.1

Browser: FireFox 54.0.1

Ich schrieb einen einfachen JavaScript-Alarm für die Prüfung, sondern auch von Selen zu stoppen. von Selen eigener 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

Selen-ide/content/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

Zeigen Sie Ihre Selen Skript – Liam

+0

Nur Update wurde die Ausnahme hier kommen 'self.windowMethods [ 'alert'] Anruf (self.window, Alarm);.' – Jotzuc

Antwort

0

Dies liegt daran, dass die Funktionsaufrufe werden zur Laufzeit tatsächlich außer Kraft gesetzt werden. Fügen Sie unten Javascript-Code zur Seleniumkern-Benutzererweiterung hinzu, nach Neustart kann dieses Problem beheben.

//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];"); 
};