使用Selenium Webdriver(Java)的html表行计数 [英] html table row count using Selenium Webdriver (Java)

查看:92
本文介绍了使用Selenium Webdriver(Java)的html表行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Selenium Webdriver-Java计算HTML表中的总行数(不包括标题).

I am trying to count the total number of rows (excluding header) in my HTML table using Selenium Webdriver-Java.

有人可以在正确的方向上指导我吗?

Can someone please guide me in correct direction regarding the steps for the same?

提前谢谢!

推荐答案

如果您可以在表格周围提供HTML,我们可以为您提供更准确的选择器.这样的事情应该起作用.希望你能明白!

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!

List<WebElement> rows = driver.findElements(By.cssSelector("table#dummyTable>tbody>tr"));
System.out.println("Total number of rows :"+ rows.size());

或使用xpath

List<WebElement> rows = driver.findElements(By.xpath(".//table[@id='dummyTable']/tbody/tr"));
System.out.println("Total number of rows :"+ rows.size());

这篇关于使用Selenium Webdriver(Java)的html表行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆