在页面上,我具有表导出列表元素,该元素会在几秒钟到几分钟(待处理,正在处理和已完成)之后更改,或者进度条已100%完成。从:
<p id="2c92c0f953cfa2d80153e8409eggFeb9" class="ares_txt15"> Pending </p> </td>
至:
<p id="22c92c0f953cfa2d80153e6404bcc12c2" class="ares_txt15"> Completed
<script type="text/javascript"> var newPro0 = new ProgressBar('100'-0).appendTo('2c92c08653cf9ce60153e6cde69d57da'); </script>
<div class="iblock" style="vertical-align: middle; padding-left: 5px;">
<div class="iblock" style="width: 80px; height: 8px; border: 1px solid rgb(153, 153, 153); padding: 1px; font-size: 0px; vertical-align: middle; line-height: 0px;">
<div class="iblock" style="width: 80px; height: 8px; background: rgb(115, 194, 56) none repeat scroll 0% 0%; vertical-align: middle; font-size: 0px; line-height: 0px;"/>
</div>
<span class="iblock" style="padding: 0px 5px; line-height: 11px; vertical-align: middle;">100%</span>
</div>
</p
这就是我所拥有的:
>>> all_data = browser.find_elements_by_xpath("//*[@class='ares_txt15']")
>>> for row in all_data:
print(row.text)
Pending
Completed 100%
Completed 100%
Completed 100%
Completed 100%
Completed 100%
try:
WebDriverWait(browser, 80).until(EC.presence_of_element_located((By.XPATH, '//*[@class="ares_text15" and contains(text(), "Completed 100%")]')))
except TimeoutException:
raise Exception('Unable to find text in this element after waiting 80 seconds')
Traceback (most recent call last):
File "<pyshell#56>", line 4, in <module>
raise Exception('Unable to find text in this element after waiting 80 seconds')
Exception: Unable to find text in this element after waiting 80 seconds
text()=="Completed"
应该text()="Completed"
与一个=
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@class="ares_text15" and text()="Completed"]')))
您也可以尝试contains
代替=
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@class="ares_text15" and contains(text(), "Completed")]')))
您也可以尝试使用 text_to_be_present_in_element
WebDriverWait(self.driver, 10).until(EC.text_to_be_present_in_element((By.CLASS_NAME, 'ares_text15'), 'Completed'))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句