最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Selenium: How to wait for a element's text to change - Stack Overflow

programmeradmin0浏览0评论

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 bee

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

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 bee

 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'); 
Share Improve this question edited Sep 16, 2011 at 9:33 borrible 17.4k8 gold badges56 silver badges77 bronze badges asked Sep 15, 2011 at 22:14 La LaLa La 551 silver badge4 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

Please try to change xpath as follows.

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

or

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

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 parison 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 parison.

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

Implicit wait?

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
发布评论

评论列表(0)

  1. 暂无评论