Justyna
Justyna

Reputation: 23

Selenium+python: Waiting on changes in style

On page I have HTML element which changes after a few seconds (to few minutes) from:

<div style="opacity: 1; width: 100%;" id="progressbar-overlay" class="wings-progressbar-overlay"></div>

to:

<div style="opacity: 0; width: 0%;" id="progressbar-overlay" class="wings-progressbar-overlay"></div>

It's part of loader. I want to wait till this element change.

I've tried with this:

element = self.check_element(By.ID, "progressbar-overlay", "Progressbar wasn't displayed", tekst)

    for x in range(0, 120):
        if element.value_of_css_property("opacity")==1:
            print element.value_of_css_property("opacity") + " not yet"
        else: 
            print element.value_of_css_property("opacity") + " end"
            break

but result is:

1 en.

Ran 1 test in 23.021s

OK d

Why doesn't it work and how to wait on this element's change?

Upvotes: 2

Views: 1230

Answers (1)

Hassan Mehmood
Hassan Mehmood

Reputation: 1402

See the following example. This function will wait till your second div appears in DOM.

import time
...
...
def wait_for_complete_page_load(browser, total_wait=100):
    try:
        elem = browser.find_element_by_xpath('//div[contains(@style, "opacity: 0")]')
    except:
        total_wait -= 1
        time.sleep(2)
        if total_wait > 1: wait_till_page_loaded(browser, total_wait)

Upvotes: 2

Related Questions