'How to wait until page has finished loading

I am automating the android mobile application with Selenium using explicit wait with expected conditions to click buttons. There is a loading overlay that is displayed after form submission. The loading overlay is also called when a post & get request is happening in the background. I am trying to click an element, but the loading overlay disrupts the button click as nothing can be clicked when there is an overlay. Is there a way to check if the post&get request has been completed in selenium? I can't use expectedConditions.invisibilityOfElement as the loading overlay display time is somewhat inconsistent



Solution 1:[1]

You can utilize the Javascript Executor and hook into the javascript that is running on the page and wait until your javascript returns a specific value.

Or you can use a mutation observer activated via javascript to wait or keep track of element changes as your condition.

In your case, you can attach a mutation observer to the element of the page where the progress bar is attached to as your first condition.

Once that condition is met, you can wait until the progress bar is gone as your second condition.

Then you should be good to go.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marek Andreansky