Reputation: 1511
I am trying to check the status of <td>
element which has status change from "Running"
to "Success"
. The status change might take around 1 minute or for every few seconds i need to retry checking the status of element. Can someone help me how to achieve this , following is the html structure and snippet that i am trying.
Running
<tbody id="workflows">
<tr id="row8ff2244a64f3e7180164ff637c574d24" class="selected">
<td><span class="wf-status running" id="status8ff2244a64f3e7180164ff637c574d24">Running</span></td>
<td>Copy of Discovery v4madhu-test3-automate</td>
<td>03 Aug 16:14</td>
<td>autotest</td>
<td>dmatarget14.hpeswlab.net</td>
<td></td>
<td></td>
</tr>
</tbody>
Success
<tbody id="workflows">
<tr id="row8ff2244a64f3e7180164ff637c574d24" class="selected">
<td><span class="wf-status wfsuccess" id="status8ff2244a64f3e7180164ff637c574d24">Success</span></td>
<td>Copy of Discovery v4madhu-test3-automate</td>
<td>03 Aug 16:14</td>
<td>autotest</td>
<td>dmatarget14.hpeswlab.net</td>
<td></td>
<td></td>
</tr>
</tbody>
sample code
timeout = 60
maxtime = time.time() + timeout
result = None
while result is "SUCCESS":
try:
# connect
result = driver.find_element_by_xpath('//td[contains,"dmatarget14.hpeswlab.net"] and td[contains,"Success"]/ancestor::tr')
time.sleep(5)
except:
if time.time() > maxtime:
raise Exception
Upvotes: 1
Views: 1451
Reputation: 193188
To validate the status of the <td>
element to change the text from Running to Success you can use either of the following solutions:
text_to_be_present_in_element
and CSS_SELECTOR
:
element = WebDriverWait(driver, 20).until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, "tbody#workflows>tr.selected>td>span.wf-status.wfsuccess"), "Success"))
text_to_be_present_in_element_value
and CSS_SELECTOR
:
element = WebDriverWait(driver, 20).until(EC.text_to_be_present_in_element_value((By.CSS_SELECTOR, "tbody#workflows>tr.selected>td>span.wf-status.wfsuccess"), "Success"))
Upvotes: 0
Reputation: 270
You can try this code :
WebDriverWait(driver, 60).until(
EC.presence_of_element_located((By.XPATH, '//td[contains,"dmatarget14.hpeswlab.net"] and td[contains,"Success"]/ancestor::tr'))
Upvotes: 0
Reputation: 52675
You can apply below solution:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
timeout = 60
WebDriverWait(driver, timeout).until(EC.presence_of_element_located((By.XPATH, '//tbody[@id="workflows"]//td[.="Success"]')))
This code should allow you to wait up to 60
seconds and return True
once td
with text Success
appeared in DOM or TimeoutException
in case no element appeared after 60 seconds passed
Upvotes: 3