Waiting for the loading icon to finish. Selenium Python. “while” helps again.

So many pages now have the “loading ..” icon while waiting for something.
A simple way to wait while it’s done, again with “while” statement:

while self.driver.find_element_by_css_selector("div#loadingIcon").get_attribute("style") == "display: block;":
                time.sleep(0.5)

In this case the div had “display: block;” when visible (when it’s loading) and “display: none;” when it was not loading.