La La
La La

Reputation: 55

Selenium: How to wait for a element's text to change

I have an element whose status (in text form) changes depending on a contextmenu associated with it.
Here is the element:

td id="A" name="status"> StatusStart  </td>     

Upon some action, this can become

 td id="A" name="status"> StatusDone  </td>      

I want to wait for the text change to happen, using waitForCondition.
So far, i've tried:

selenium.waitForCondition("selenium.isElementPresent(\"//td[@name='status' and text()='StatusDone']\");", "10000");    

but that doesn't work because the text is not part of the td element.
In JavaScript, i see something like:

function myfunc() {        
window.getGlobal().addSelectGroup('status'); window.getGlobal().addSelectItem('status','StatusStart'); 

Upvotes: 5

Views: 4227

Answers (4)

Fletch
Fletch

Reputation: 5219

Implicit wait?

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Upvotes: 0

Ross Patterson
Ross Patterson

Reputation: 9570

You say "that doesn't work because the text is not part of the td element". Which is odd, because the HTML you show says that the text is part of the TD element. And the waitForCondition() you've tried is exactly the way to do it. My best guess is that the TD text is not exactly "StatusDone", but rather " StatusDone " (based on your HTML). The comparison will never match if so. There are obvious ways to fix that - add the spaces to the constant, or use contains(text(), 'StatusDone') instead of the comparison.

Upvotes: 1

rs79
rs79

Reputation: 2321

You could implement a repetitive storeText(css=td[name=status],var_name) within a do-while (java) loop and break once var_name="StatusDone"

Upvotes: 0

Msyk
Msyk

Reputation: 672

Please try to change xpath as follows.

//td[@name='status' and .//text()='StatusDone']

or

//td[@name='status' and contains(.//text(),'StatusDone')]

Upvotes: 4

Related Questions