简体   繁体   中英

Selenium IDE is stopping javascript

When using Selenium IDE to record actions on a web page the application is stopping the JavaScript and displays the error message "too much recursion."

I'm using Selenium IDE 2.9.1.1 on FireFox 54.0.1

I wrote a simple javascript alert for testing, but it is also being stopped by Selenium.

<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

selenium-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);
   }
}

This is because the function calls are actually being overridden at runtime by Selenium's own JavaScript. Add below Javascript code to selenium core user extension, after restart can fix this problem.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM