1

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?

Prophet
  • 32,350
  • 22
  • 54
  • 79
Injoo Kim
  • 17
  • 3
  • I'm not familiar with stackoverflow I did not know that I need to accept answers I will do it thx anyway – Injoo Kim Dec 19 '21 at 15:53
  • You don't have to do that, but 1) This makes indication that the problem is resolved 2) It's a way to say "Thanks" to person who helped you. This gives some points both to you and to the person who helped you. – Prophet Dec 19 '21 at 15:56
  • I got it sir thank you for letting me know that ! :^) – Injoo Kim Dec 19 '21 at 16:02

2 Answers2

1

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)
Prophet
  • 32,350
  • 22
  • 54
  • 79
  • sorry for late reply! I just waited for it works and it works well! Thank you! have a good day! – Injoo Kim Dec 19 '21 at 16:42
  • It's OK. You do not have to accept the answers automatically. In case it works - accept the answer, otherwise let the answerer know if it did not work, what error appeared etc. – Prophet Dec 19 '21 at 16:44
0

As the innerText/innerHTML will eventually turn out as 100 instead of presence_of_element_located() you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using xpath and innerText:

    progress =  WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH,"//div[@role='progressbar' and text()='100%']")))
    
  • Using xpath and aria-valuenow attribute:

    progress =  WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH,"//div[@role='progressbar' and @aria-valuenow='100%']")))
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352