1

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

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

7 Comments

This, but I would use a css-selector instead of an xpath-selector to make the selector easier to handle and more readable. The OP uses xpath though, so I understand why you use xpath in the answer as well
CSS selector (in Selenium) does not allow you to locate element by its text content. If OP wants to wait for "Success" I thought it would better to use this selector. But there might be a lot of other options..
The td-element changes class from running to wfsuccess which imo is a more robust selector than looking at the text, but yeah I understand what you mean. The css-selector would be something like "td.wfsuccess", or even better "#status8ff2244a64f3e7180164ff637c574d24.wfsuccess" even though the ID looks auto-generated (which I consider a code smell)
@Andersson my td is unique (<td>dmatarget14.hpeswlab.net</td> ) for every tr . Can you please help with correct XPATH expression
//tbody[@id="workflows"]//td[.="Success" and following-sibling::td[.="dmatarget14.hpeswlab.net"]]
|
0

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

Comments

0

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"))
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.