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