seleniumtestingautomated-testskatalon-studiokatalon-recorder

Count items, rows, users, etc in Katalon Studio


I am having some problem with Katalon Studio.

Can I somehow count items on the page by class or something?

I can do it with JavaScript but I don't know how to do it with groovy language in Katalon studio.

document.getElementsByClassName("").length

I'm trying to convert this JavaScript code into groovy but nothing happens.


Solution

  • I think you can use the same method of size() like done in Table:

    See documentation.

    import org.openqa.selenium.By as By
    
    import org.openqa.selenium.WebDriver as WebDriver
    
    import org.openqa.selenium.WebElement as WebElement
    
    WebDriver driver = DriverFactory.getWebDriver()
    'To locate table'
    WebElement Table = driver.findElement(By.xpath("//table/tbody"))
    'To locate rows of table it will Capture all the rows available in the table'
    List<WebElement> rows_table = Table.findElements(By.tagName('tr'))
    'To calculate no of rows In table'
    int rows_count = rows_table.size()
    println('No. of rows: ' + rows_count)
    

    Hope this helps you!