2016-04-11 174 views
0

在頁面上,我有一個表格導出列表元素,它在幾秒鐘之後更改爲幾分鐘(等待,正在處理和已完成)或進度條完成爲100% 。 來源:Selenium python如何等待創建元素

<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 
+0

升起時間爲10秒60。看看它是否會爲你工作? –

回答

1

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')) 
+0

我嘗試了上面的建議代碼。仍然得到超時異常。你能看到上面 –

+0

@RicardLe我增加了另一個解決方案 – Guy

+0

是的,這是幻想。這個對我有用。謝謝Guy –

相關問題