0
我想验证列表框中添加的文本是否已成功删除。用C#处理Selenium中这种情况的最佳方式是什么?硒 - 如何检查列表框中是否存在文本
下面给出了我目前使用的代码。
//Verify that the subject is added and then deleted
public static void VerifySubjectDel()
{
string subjectAddValue = GenerateRandomAlphaCode(200);
productPage.subjectAddTxtBx.SendKeys(subjectAddValue);
productPage.subjectAddBtn.Click();
IWebElement elem = WebDriver.FindElement(By.Id("Subjects_ListBox"));
SelectElement selectList = new SelectElement(elem);
IList<IWebElement> options = selectList.Options;
if (options.ToList().Any(tagname => tagname.Text.Contains(subjectAddValue)))
{
Assert.IsTrue(true);
selectList.SelectByText(subjectAddValue);
productPage.subjectDelBtn.Click();
WebDriver.SwitchTo().Alert().Accept();
bool subjectDel = WebDriver.FindElements(By.XPath(".//*[@id='Subjects_ListBox']//option[contains(text(),'" + subjectAddValue + "')]")).Count == 0;
if (subjectDel)
{
Assert.IsTrue(subjectDel);
}
else
Assert.IsTrue(subjectDel, "Subject not deleted successfully");
}
else
Assert.IsTrue(false, "The Subject added is not present in the Subject-ListBox");
}
尝试使用** CollectionAssert.DoesNotContain()** – Sudeepthi