pythonseleniumwebdriverwaitexpected-condition

Selenium wait for progress bar Python?


I still not get it with waiting progress bar with selenium for next code

<div data-v-a5395076="" class="progress">
<div data-v-a5395076="" role="progressbar" aria-valuenow="98.4" 
aria-valuemin="0" aria-valuemax="100" class="progress-bar progress-bar-striped active" 
style="width: 98.4%;">98.4%</div>

this is what I'm trying to wait until 100%
and I cannot get the text nor attribute I was trying to get_attribute('aria-valuenow').text but I assume thats not it.

while True:
            try:
                progress =  WebDriverWait(driver, 5).until(
                EC.presence_of_element_located((By.CSS_SELECTOR,".progress-bar.progress-bar-striped.active")))
                progressCondition =progress.get_attribute('aria-valuenow').text
                print(progressCondition)
                while True:
                    if progressCondition == '100':
                        break
                    else:
                        print(progress)
                        time.sleep(1)
                break
            except:
                print('Progress Not Found')
                time.sleep(1)
                timer += 1
                if timer > 30:
                    break
                else:
                    continue

how?


Solution

  • I guess this can help:

    1. Change presence_of_element_located by visibility_of_element_located since presence_of_element_located returns the web element while it is still not fully rendered, just exists on the page, but still not visible while visibility_of_element_located waits for more mature elements state when it is already visible.
    2. Remove .text from progress.get_attribute('aria-valuenow').text
      get_attribute() method returns string value itself. While .text extracts text from web element.
      So your code may look like the following:
    progress =  WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CSS_SELECTOR,".progress-bar.progress-bar-striped.active")))
    progressCondition =progress.get_attribute('aria-valuenow')
    print(progressCondition)