我已经搜索了很多,以便在Selenium webdriver中找到处理表格的示例。所有样本仅针对仅有5行或10行的表格进行说明。如何处理像吹动示例的表格:
https://www.redmine.org/projects/redmine/issues
如何浏览这些表的所有页面并获取“主题”列的示例?
简单表格的示例:
{{3} }
答案 0 :(得分:2)
这段代码可能有用。在这里,我将所有问题都解决并在控制台中打印,您可以编写内部for循环所需的任何断言语句。
driver.get("https://www.redmine.org//projects//redmine//issues");
driver.manage().window().maximize();
driver.findElement(By.xpath(".//*[@class='per-page']/a[2]")).click();
int num_of_clicks = Integer.parseInt(driver.findElement(
By.xpath(".//*[@id='content']/p[1]/a[3]")).getText());
for (byte i = 1; i < num_of_clicks; i++) {
List<WebElement> records_in_page = driver.findElements(By.xpath(".//*[@class='list issues']/tbody/tr"));
for (byte j = 0; j < records_in_page.size(); j++) {
String Issue_Subject = driver.findElement(
By.xpath(".//*[@class='list issues']/tbody/tr[" + (j+1)
+ "]/td[5]")).getText();
System.out.println(Issue_Subject);
}
driver.findElement(By.xpath(".//*[@class='next']")).click();
}
答案 1 :(得分:1)
感谢Krishna Reddy,这是因为有人想在C#中使用它:
driver.Navigate().GoToUrl("https://www.redmine.org//projects//redmine//issues");
driver.manage().window.maximize();
driver.FindElement(By.XPath(".//*[@class='per-page']/a[2]")).click();
int num_of_clicks = Int32.Parse(driver.FindElement(
By.XPath(".//*[@id='content']/p[1]/a[3]")).Text);
for (byte i = 1; i < num_of_clicks; i++) {
IList<IWebElement> records_in_page = driver.FindElements(By.XPath(".//*[@class='list issues']/tbody/tr"));
for (byte j = 0; j < records_in_page.Count; j++) {
String Issue_Subject = driver.FindElement(
By.XPath(".//*[@class='list issues']/tbody/tr[" + (j+1)
+ "]/td[5]")).Text;
Console.WriteLine(Issue_Subject);
}
driver.FindElement(By.XPath(".//*[@class='next']")).click();
}