Count element presences on page


#1

I would like to count, how many times are the same element present on page. I am looking for similar method than Verify Elements Count for webservices.


#2

Try something like this, to print number of elements with “your-class” class. Change locators according to your need.

WebDriver driver = DriverFactory.getWebDriver()
def eleCount = driver.findElements(By.className("your-class")).size()
println eleCount 

#3

I imported com.kms.katalon.core.webui.driver.DriverFactory, but got error message:

71.groovy: 46: unable to resolve class WebDriver


#4

You’ll need this

import org.openqa.selenium.WebDriver

Btw, you can pres ctrl+shift+o to import missing libraries.