在深入研究WatiN的約束條件後,我最終找到了自己的解決方案。
這裏的解決方案:
public class TextConstraint : Constraint
{
private readonly string _text;
private readonly bool _negate;
public TextConstraint(string text)
{
_text = text;
_negate = false;
}
public TextConstraint(string text, bool negate)
{
_text = text;
_negate = negate;
}
public override void WriteDescriptionTo(TextWriter writer)
{
writer.Write("Find text to{0} match {1}.", _negate ? " not" : "", _text);
}
protected override bool MatchesImpl(IAttributeBag attributeBag, ConstraintContext context)
{
return (attributeBag.GetAdapter<Element>().Text == _text)^_negate;
}
}
和更新的擴展方法:
public static void WaitForTextChange(this IE ie, Element element)
{
string old = element.Text;
element.WaitUntil(new TextConstraint(old, true));
}
它假定舊值將改變以前那麼有競爭條件,如果稍有機會讀你在啓動更新後使用它太久了,但它對我很有用。
其實。我遇到了另一個問題。有時我更新的價格不會改變,在這種情況下,我想超時,然後繼續下一個用戶操作,但使用 .WaitUntil(new TextConstraint(old,true),2000); 只是卡住了。 – 2009-10-22 08:01:07