我正在尝试自动化UI页面,如果未填充必填字段,将显示多条验证消息。
确保所有内容都显示的最佳方式是什么?
有7种不同的错误消息
<span for="JobTitle">The Job Title field is required.</span>
<span for="JobReference">The Reference field is required.</span>
<span for="LocationSelect">The Location field is required.</span>
<span for="ReportsTo">The Reports To field is required.</span>
<span for="DirectReports">The Direct Reports To field is required.</span>
<span for="DepartmentSelect">The Department field is required.</span>
<span for="Type">The Type field is required.</span>
我是否需要为每封邮件做类似的事情?
public static void Validation()
{
Driver.Instance.FindElement(By.XPath("html/body/section[2]/div/div/div/div/form/div[1]/div[2]/span/span"));
}
答案 0 :(得分:0)
Driver.Instance.FindElement();
会为您提供与此xpath
匹配的第一个元素。如果您需要检查多个,则需要使用FindElement
Driver.Instance.FindElements(By.XPath("html/body/section[2]/div/div/div/div/form/div[1]/div[2]/span/span"));
如果要检查它们是否全部显示,请使用循环
进行迭代public static bool Validation()
{
IList<IWebElement> messages = Driver.Instance.FindElements(By.XPath("html/body/section[2]/div/div/div/div/form/div[1]/div[2]/span/span"));
foreach (IWebElement message in messages)
{
if (!message.Displayed)
{
return false; // one of the messages isn't displayed
}
}
return true; // all the messages are displayed
}
答案 1 :(得分:0)
使用 CollectionAssert.AreEqual()来比较验证消息。