I still not get it with waiting progress bar with selenium for next code
<div data-v-a5395076="" >
<div data-v-a5395076="" role="progressbar" aria-valuenow="98.4"
aria-valuemin="0" aria-valuemax="100"
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?
CodePudding user response:
I guess this can help:
- Change
presence_of_element_located
byvisibility_of_element_located
sincepresence_of_element_located
returns the web element while it is still not fully rendered, just exists on the page, but still not visible whilevisibility_of_element_located
waits for more mature elements state when it is already visible. - Remove
.text
fromprogress.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)
CodePudding user response:
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%']")))