Problem to solve: Count the number of rows in a table
- Using Chrome navigate to HTML Tables
- Open Chrome DevTools by pressing F12.
- Click on the ‘Elements’ tab.
- Press the keyboard Ctrl+F keys.
- Search for: (//tbody)[1] and press Enter.
- Right-click on
<table class="ws-table-all" id="customers"> - Click ‘Copy’ > ‘Copy Xpath’
- 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")



