I am trying to figure out how to capture the count of pending xmlhttprequests in a web page using javascript while working with selenium and python.
It seems like there is a useful link that could help me get this information, but I'm having trouble getting the logic right. The XMLHttpRequest.active always returns zero for me. Can someone explain what I might be missing or suggest a different approach?
Get count of network calls happening in a web page
Shared by user
To dynamically inject the required JavaScript code into the screen, I have included the following script:
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);")