[英]Selenium IDE is stopping javascript
当使用 Selenium IDE 记录网页上的操作时,应用程序会停止 JavaScript 并显示错误消息“递归过多”。
我在 FireFox 54.0.1 上使用 Selenium IDE 2.9.1.1
我写了一个简单的 javascript 警报进行测试,但它也被 Selenium 阻止了。
<html>
<head>
<script>
function hello(){
alert("Hello\nHow are you?");
}
</script>
</head>
<body>
<input type="button" onclick="hello();" value="Say Hi" />
</body>
</html>
硒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);
}
}
这是因为函数调用实际上在运行时被 Selenium 自己的 JavaScript 覆盖了。 在 selenium 核心用户扩展中添加下面的 Javascript 代码,重启后可以解决这个问题。
//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];");
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.