<div class="validation-summary-errors">
<span>Please check the following entries:</span>
<ul>
<li>Please select a client account</li>
<li>Please select a beneficiary account</li>
</ul>
</div>
public virtual T VerifyAmountValidationMessages()
{
HtmlDiv error = new HtmlDiv(_browserWindow);
error.SearchProperties[HtmlDiv.PropertyNames.Class] = "validation-summary-errors";
var errors = error.FindMatchingControls();
var errorLi = error.GetChildren()[0];
foreach (var item in errors)
{
Assert.IsTrue(item.GetProperty("InnerText").ToString().Contains("Please check the following entries:\r\nPlease select a client account\r\nPlease select a beneficiary account"));
}
return (T)this;
}
如何使用getChildren迭代所有lis并声明每个Li的内部文本,我可以分别访问span元素,但我想单独访问Li?现在,我要断言全文,这根本不是正确的方法。
答案 0 :(得分:0)
ul元素将为errors.GetChildren()[0];
,它们将在其子元素上循环。
<div class="validation-summary-errors">
<span>Please check the following entries:</span>
<ul>
<li>Please select a client account</li>
<li>Please select a beneficiary account</li>
</ul>
</div>
public virtual T VerifyAmountValidationMessages()
{
HtmlDiv error = new HtmlDiv(_browserWindow);
error.SearchProperties[HtmlDiv.PropertyNames.Class] = "validation-summary-errors";
var errors = error.FindMatchingControls();
var errorul = error.GetChildren()[1];
foreach (var item in errors
{
// check individual li items
}
return (T)this;
}
这似乎是一个脆弱的测试,请考虑是否对显示错误的方式进行了任何更改,您必须重写测试。