简体   繁体   English

硒:如何等待元素的文本更改

[英]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. 我想使用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. 但这不起作用,因为文本不是td元素的一部分。
In JavaScript, i see something like: 在JavaScript中,我看到类似以下内容:

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

Please try to change xpath as follows. 请尝试如下更改xpath。

//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". 您说“那不起作用,因为文本不是td元素的一部分”。 Which is odd, because the HTML you show says that the text is part of the TD element. 这很奇怪,因为显示的HTML表示文本 TD元素的一部分。 And the waitForCondition() you've tried is exactly the way to do it. 而您尝试过的waitForCondition()正是这样做的方法。 My best guess is that the TD text is not exactly "StatusDone", but rather " StatusDone " (based on your HTML). 我最好的猜测是,TD文本不是完全 “ StatusDone”,而是“ StatusDone”(基于您的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. 有解决此问题的明显方法-在常量中添加空格,或使用contains(text(), 'StatusDone')代替比较。

隐式等待?

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

您可以在do-while( java )循环中实现重复的storeText(css=td[name=status],var_name)break一次var_name="StatusDone"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM