【发布时间】:2021-01-15 08:45:39
【问题描述】:
如前所述,如何在 javascript 中捕获 xmlhttprequests 未决计数。我在 python 中使用 selenium。
想要捕获等待完成的 xmlhttprequests 的数量。
找到一个有用的链接并尝试了答案中提到的以下javascript。但是没有正确理解并且总是将 XMLHttpRequest.active 设为零。谁能解释一下逻辑或任何其他建议。
Get count of network calls happening in a web page
来自用户https://stackoverflow.com/users/2887618/florent-b
我已经包含了动态注入屏幕的javascript。
jscript = ("(function() {" +
" var send = XMLHttpRequest.prototype.send;" +
" var release = function(){ --XMLHttpRequest.active };" +
" var onloadend = function(){ setTimeout(release, 1) };" +
" XMLHttpRequest.active = 0;" +
" XMLHttpRequest.prototype.send = function() {" +
" ++XMLHttpRequest.active;" +
" this.addEventListener('loadend', onloadend, true);" +
" send.apply(this, arguments);" +
" };})();")
print(jscript)
driver.execute_script(jscript)
isxmlhttpactive = driver.execute_script("return (window.XMLHttpRequest.active);")
【问题讨论】:
标签: javascript python-3.x selenium-webdriver xmlhttprequest