我需要在Selenium Web驱动程序PhantomJs的当前文档中找到有多少ajax调用待处理,我没有引用ajax调用对象
我尝试执行此javascript:
var s_ajaxListener = new Object();
s_ajaxListener.tempSend = XMLHttpRequest.prototype.send;
function increaseCounter () {
window.ajaxRequestCount = window.ajaxRequestCount + 1;
}
function decreaseCounter() {
window.ajaxRequestCount = window.ajaxRequestCount - 1;
}
XMLHttpRequest.prototype.send = function() {
increaseCounter()
s_ajaxListener.tempSend.apply(this, arguments);
this.addEventListener("progress", increaseCounter, false);
this.addEventListener("load",decreaseCounter , false);
this.addEventListener("error", decreaseCounter, false);
this.addEventListener("abort", decreaseCounter, false);
}
但是,执行此print "ax-count: ", browserInstance.execute_script("return window.ajaxRequestCount")
输出时:None