[英]Handle multiple pages table in Selenium Webdriver
我进行了大量搜索,以找到用于在Selenium Webdriver中处理表格的示例。 所有示例仅针对仅5或10行的表进行说明。 我如何处理表格如打击示例: https : //www.redmine.org/projects/redmine/issues
如何浏览此类表的所有页面,例如获取“主题”列的vlues?
简单表的示例示例:
http://toolsqa.com/selenium-webdriver/handle-dynamic-webtables-in-selenium-webdriver/
这段代码可能有效。 在这里,我得到所有问题的主题并将其打印在控制台中,您可以在内部for循环中编写所需的任何assert语句。
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();
}
感谢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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.