I am asking for generally checking if all elements of a page has been loaded. Is there a way to check that basically?
In the concrete example there is a page, I click on some button, and then I have to wait until I click on the ‘next’ button. However, this ‘Next’ button is available, selectable and clickable ALL THE TIME. So how to check with selenium that ‘state'(?) of a page?
As a reminder: This is a question about selenium and not the quality of the webpage in question….
As your question is about if there is a way with python-selenium to wait until all elements of a page has loaded, the Answer is No.
An Alternate Approach
Fundamentally, you can write a line of code (or implement it through a function) to check for the ‘document.readyState’ == “complete” as follows :
Writing the above mentioned line to wait for Page Loading is implemented by default through Selenium. So rewriting the same is a complete overhead. The client (i.e. the Web Browser) will never return the control back to the WebDriver instance until and unless
'document.readyState' is equal to
"complete". Once this condition is fulfilled Selenium performs the next line of code.
It’s worth to mention that though the client (i.e. the Web Browser) can return back the control to the WebDriver instance once
'document.readyState' equal to "complete" is achieved, it doesn’t guarantees whether all the WebElements on the new HTML DOM are present, visible, interactable and clickable.
So, as per our requirement, if the next *WebElement with which you have to interact is not interactable by the time
'document.readyState' equal to "complete" is achieved, you have to induce WebDriverWait inconjunction with a matching expected_conditions with respect to the individual WebElement. Here are a few of the most used expected_condition:
You can find a couple of relevant discussions in:
Reliably determining whether a page has been fully loaded can be challenging. There is no way to know if all the elements have been loaded just like that. You must define some “anchor” points in each page so that as far as you aware, if these elements has been loaded, it is fair to assume the whole page has been loaded. Usually this involves a combination of tests. So for example, you can define that if the below combination of tests passes, the page is considered loaded:
document.readyState === 'complete'
- “Anchor” elements
- All kinds of “spinners”, if exist, disappeared.
There is something called the
The document is still being loaded, no css or other resources are available
The document has been loaded, no css or other resources are available
Both the document and the css / other resources are loaded
You’re looking for at least Interactive. You can retrieve the state by calling