[英]Selenium C# Tables - reading each values and adding them and Returning as List<string>
[英]Selenium C# Getting values from a Column of a table and turn them into a list of String
我需要获取 2 列的值并将它们转换为字符串列表。有人可以告诉我怎么做吗? 非常感谢
IWebElement tableElement = driver.FindElement(By.XPath("/html/body/app-root/ng-component/div/div/div[2]/ng-component/div[2]/div/p-table/div/div/div/div[2]/table/tbody"));
IList<IWebElement> rows = tableElement.FindElements(By.TagName("tr"));
IList<IWebElement> rowtd;
var Code1 = new List<string>();
foreach (IWebElement row in rows)
{
rowtd = tableElement.FindElements(By.TagName("td"));
var tableData = rowtd.ToString();
Code1.Add(tableData);
}
我正在测试搜索 function,我想将结果与输入进行比较。 搜索function的完整测试代码:
public void Search_XE_with_Name(String Name)
{
Login();
driver.Navigate().GoToUrl(homeURL + "/app/admin/xe-group11");
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
Thread.Sleep(8000);
//Act
driver.FindElement(By.Name("xE_NAME")).Clear();
driver.FindElement(By.Name("xE_NAME")).SendKeys(Name);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(7);
IWebElement ele = driver.FindElement(By.XPath("/html/body/app-root/ng-component/div/div/div[2]/ng-component/form/div/div[1]/div/div/div/span[3]/button/i"));
IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
executor.ExecuteScript("arguments[0].click();", ele);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
//IWebElement tableElement = driver.FindElement(By.XPath("/html/body/app-root/ng-component/div/div/div[2]/ng-component/div[2]/div/p-table/div/div/div/div[2]/table/tbody"));
//IList<IWebElement> rows = tableElement.FindElements(By.TagName("tr"));
//List<String> Name1 = new List<String>();
IWebElement tableElement = driver.FindElement(By.XPath("/html/body/app-root/ng-component/div/div/div[2]/ng-component/div[2]/div/p-table/div/div/div/div[2]/table/tbody"));
IList<IWebElement> rows = tableElement.FindElements(By.TagName("tr"));
//IList<IWebElement> rowtd;
List<string> Code1 = new List<string>();
foreach (IWebElement row in rows)
{
var secondColumn = tableElement.FindElements(By.TagName("td"))[2];
Code1.Add(secondColumn.Text);
}
foreach (String codes in Code1)
{
Assert.AreEqual(codes, Name);
}
driver.Close();
}
您应该能够只使用索引来始终获取每行的第二列...
foreach (IWebElement row in rows)
{
var secondColumn = tableElement.FindElements(By.TagName("td"))[1];
Code1.Add(secondColumn.Text);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.