在 Katalon Studio 中计算项目、行、用户等

Count items, rows, users, etc in Katalon Studio

我在使用 Katalon Studio 时遇到一些问题。

我可以通过 class 或其他方式对页面上的项目进行计数吗?

我可以使用 JavaScript 但我不知道如何使用 groovy Katalon 工作室中的语言。

document.getElementsByClassName("").length

我正在尝试将此 JavaScript 代码转换为 groovy 但没有任何反应。

我认为您可以使用 size() 中相同的方法,就像在 Table 中所做的那样:

参见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)

希望对您有所帮助!

这样做

WebDriver driver = DriverFactory.getWebDriver()
def eleCount = driver.findElements(By.className("your-class")).size()
println eleCount //prints out the number of the elements with "your-class" class

您还可以使用 WebUiBuiltInKeywords 来查找以下 URL 中指定的 WebElements。它将 return 与定位器匹配的元素列表。

static List<WebElement> findWebElements(TestObject to, int timeOut)
// Internal method to find web elements by test object

例子

def elements = WebUiBuiltInKeywords.findWebElements(to, 5)
println elements.size()