Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'); 
like image 450
La La Avatar asked Sep 15 '11 22:09

La La


2 Answers

Please try to change xpath as follows.

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

or

//td[@name='status' and contains(.//text(),'StatusDone')]
like image 91
Msyk Avatar answered Sep 23 '22 05:09

Msyk


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.

like image 44
Ross Patterson Avatar answered Sep 26 '22 05:09

Ross Patterson