Problem to solve: Count the number of rows in a table

Problem to solve: Count the number of rows in a table

  1. Using Chrome navigate to HTML Tables
  2. Open Chrome DevTools by pressing F12.
  3. Click on the ‘Elements’ tab.
  4. Press the keyboard Ctrl+F keys.
  5. Search for: (//tbody)[1] and press Enter.
  6. Right-click on <table class="ws-table-all" id="customers">
  7. Click ‘Copy’ > ‘Copy Xpath’
  8. Paste the //*[@id=“customers”] result into the search-box and press Enter.

Create the test case as follows:
Run the test case and then switch to the ‘Console’ view to see the results.

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import com.kms.katalon.core.webui.driver.DriverFactory

/**https://www.w3schools.com/html/html_tables.asp table row count example**/
WebUI.openBrowser('')
WebUI.navigateToUrl('https://www.w3schools.com/html/html_tables.asp')
WebDriver driver = DriverFactory.getWebDriver ()
WebElement Table = driver.findElement(By.xpath('//*[@id="customers"]/tbody'))
List<WebElement> table_row = Table.findElements(By.tagName('tr'))
int rows_count = table_row.size()
println ("found ${rows_count} rows")

1 Like

Good stuff Dave. A well put-together walk-through.

:1st_place_medal:

1 Like