使用 Selenium Webdriver (Java) 的 html 表行计数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31059635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
html table row count using Selenium Webdriver (Java)
提问by Ketan Deopujari
I am trying to count the total number of rows (excluding header) in my HTML table using Selenium Webdriver-Java.
我正在尝试使用 Selenium Webdriver-Java 计算 HTML 表中的总行数(不包括标题)。
Can someone please guide me in correct direction regarding the steps for the same?
有人可以就相同的步骤指导我正确的方向吗?
Thanks in advance!
提前致谢!
回答by nilesh
If you could provide HTML around your table, we could provide more accurate selector in your case. Something like this should work. Hope you get the idea!
如果您可以在表格周围提供 HTML,我们可以根据您的情况提供更准确的选择器。像这样的事情应该有效。希望你能明白!
List<WebElement> rows = driver.findElements(By.cssSelector("table#dummyTable>tbody>tr"));
System.out.println("Total number of rows :"+ rows.size());
or using xpath
或使用 xpath
List<WebElement> rows = driver.findElements(By.xpath(".//table[@id='dummyTable']/tbody/tr"));
System.out.println("Total number of rows :"+ rows.size());