I am facing an issue where I need to wait for the page to fully load before executing a certain action. It is important for me that the loading circle on the browser tab stops spinning before proceeding. The current Ajax function I am using does not work consistently, especially when loading a new page. My function is based on jQuery:
JavascriptExecutor jsDriver = (JavascriptExecutor) webDriver;
boolean stillRunningAjax = (Boolean) jsDriver
.executeScript("return window.jQuery != undefined && jQuery.active != 0");
return !stillRunningAjax;
If this returns false, I run it again.
However, even after my function returns true, the browser continues to load (with the loading circle spinning) for a few more seconds, sometimes even longer.
I have tried using implicitlyWait, but it interfered with my function and did not solve the problem.
Some suggest that there is no complete solution for this issue in Selenium. However, I believe there must be a way, perhaps through a JavaScript-based solution or something else.