Selenium自动测试使用列表中每个项目的链接和命令集
本文关键字:项目 链接 命令 自动测试 列表 Selenium | 更新日期: 2023-09-27 18:27:23
使用Selenium自动化测试,如何收集链接列表并对该列表中的每个项目执行相同的命令?
IList<IWebElement> reviewLinks = driver.FindElements(By.TagName("a"));
//I would like to perform the following for each Review item// in the //list
reviewLinks.First(Review => Review.Text == "Review").Click();
driver.FindElement(By.Id("ctlSeverity")).Click();
driver.FindElement(By.XPath("//*[@value='75']")).Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
driver.FindElement(By.CssSelector("#rblSelectedAction_0")).Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
driver.FindElement(By.Id("TextBox1")).SendKeys("AutoTest");
driver.FindElement(By.Id("ctlActionPlan")).SendKeys("AutoTest");
driver.FindElement(By.Id("ctlManagementResponse")).SendKeys("AutoTest");
driver.FindElement(By.Id("LinkButton1")).Click();
您可以使用一个简单的foreach循环。
foreach(var link in reviewLinks)
{
if(link.Text.Equals("Review"))
{
link.Click();
driver.FindElement(By.Id("ctlSeverity")).Click();
driver.FindElement(By.XPath("//*[@value='75']")).Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
driver.FindElement(By.CssSelector("#rblSelectedAction_0")).Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
driver.FindElement(By.Id("TextBox1")).SendKeys("AutoTest");
driver.FindElement(By.Id("ctlActionPlan")).SendKeys("AutoTest");
driver.FindElement(By.Id("ctlManagementResponse")).SendKeys("AutoTest");
driver.FindElement(By.Id("LinkButton1")).Click();
}
}