簡體   English   中英

如何使用 Selenium Java 計算表中的行數

[英]How to count the number of rows in a table using Selenium Java

我在 HTML web 頁面中有一個包含 X 行的表。 如何使用 Selenium Java 和 CSS 或 ZB6454D498635710CEA18 表達式計算行數?

我的表示例:

<tbody id="MyTableId">
<tr> First Data row</tr>
<tr> 2nd Data row</tr>
<tr> 3rd Data row<tr>
</tbody>

嘗試以下解決方案:

List<WebElement> rowCount = driver.findElements(By.xpath("//tbody[@id='MyTableId']/tbody/tr"));
System.out.println("Num rows: " + rowCount .size());

您也可以在沒有 xpath 的情況下使用以下行:

 WebElement table = driver.findElement(By.id("MyTableId"));

 int numberOfRows = table.findElements(By.tagName("tr")).size();

 System.out.println("table row count : "+numberOfRows);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM