如何通过Excel读取无限数量的行?

时间:2017-04-29 19:00:26

标签: selenium selenium-webdriver

我在Excel中有100行,我想对100行中的每一行执行测试我该怎么做?

PropertiesCollections.driver.FindElement(By.LinkText("Sales")).Click();
PropertiesCollections.driver.FindElement(By.LinkText("Sales Panel")).Click();
ExcelLib.PopulateInCollection(@"C:\Users\Numg\Desktop\webusers\Book1.xlsx");
PropertiesCollections.driver.FindElement(By.Id("web_user_user_id")).SendKeys(ExcelLib.ReadData(2, "Id"));             
PropertiesCollections.driver.FindElement(By.LinkText("Ok")).Click();
IReadOnlyCollection<IWebElement> links = PropertiesCollections.driver.FindElements(By.LinkText("Delete")); // gets a collection of elements with Delete as a link
while (links.Any()) 
{
    links.ElementAt(0).Click(); 
    PropertiesCollections.driver.FindElement(By.Id("remove_shares"));
    PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click();
    links = PropertiesCollections.driver.FindElements(By.LinkText("Delete"));
}                      PropertiesCollections.driver.FindElement(By.Id("4")).Click();
var option = PropertiesCollections.driver.FindElement(By.Id("aggrupations_653_shares"));
var SelectElement = new SelectElement(option);
SelectElement.SelectByValue("3");
PropertiesCollections.driver.FindElement(By.CssSelector("#bet-group > #send > i.fa.fa-arrow-right")).Click();
PropertiesCollections.driver.FindElement(By.Id("code")).SendKeys("testQA");
PropertiesCollections.driver.FindElement(By.CssSelector("#new_reduction > input[name=\"commit\"]")).Click();
PropertiesCollections.driver.FindElement(By.LinkText("Clear")).Click();

1 个答案:

答案 0 :(得分:0)

正如杰夫所说,你可以轻松地解决这个问题,并且可以很容易地找到解决方案,有多种方法可以逐个遍历数据行,或者可以将excel表作为任何数据类型传递,并且可以遍历循环。