How to get the length so that I can loop the elements?

I suppose you want somthing like this.

import org.openqa.selenium.By
import org.openqa.selenium.WebElement

import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

TestObject selectorMdCard = new TestObject()
selectorMdCard.addProperty("xpath", ConditionType.EQUALS, 
	"//div[@id='content']//div[1]//md-card")

// find the list of <md-card> elements
List<WebElement> mdCardList = WebUI.findWebElements(selectorMdCard, 30) 

// iterate over the list
for (mdCard in mdCardList) {
	// find a <button> in each of the <md-card>
	WebElement button = mdCard.findElement(
		By.xpath("md-card-actions[1]//md-card-icon-actions[1]//button[1]"))
               // this xpath is interpreted as relative to the <md-card> element 
	// click button
	button.click()
}

Selenium WebDriver API is here

1 Like