我需要在C#中使用Selenium验证下拉值。我有一组我希望用IWebElements IList测试的值:
IList<IWebElement> yearsDropdown = { "Select...", "Before 1996", "1996", "1997", "1998", "1999", "2000" }
我需要编写一个函数来返回下拉列表中的所有值(具有相同的确切信息),然后执行断言以确认匹配。下面是我编写的用于从下拉列表中打印值的代码,但我需要使用预期值来声明这些值:
IList<IWebElement> yearsDropdown = { "Select...", "Before 1996", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016" };
string[] dropdownListArray = new string[23];
IList<IWebElement> dropdownList = wd.FindElements(By.CssSelector("#Components_0__Entity_SourceInfo_Value_Entity_ModelYear"));
foreach(IWebElement i in dropdownList)
{
dropdownListArray[] = i.Text;
}
for(int i = 0; i < dropdownList.Count; i++)
{
Assert.AreEqual(yearsDropdown[i], dropdownList[i].Text);
}
问题是,当我尝试这个时,它从IWebElement IList dropdownList返回了整个下拉列表。我需要将IWebElement列表分解。
答案 0 :(得分:1)
List<string> yearsDropdown = new List<string>(){ "Select...", "Before 1996", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016" };
IList<IWebElement> dropdownList = wd.FindElements(By.CssSelector("#Components_0__Entity_SourceInfo_Value_Entity_ModelYear"));
foreach(IWebElement i in dropdownList)
{
Assert.AreEqual(i.Text, yearsDropdown.Text);
}
是字符串列表,而不是IWebElement。
请参阅以下代码:
{{1}}