Handling checkboxes in katalon

Hello All,

I have to loop through this box containing some checkboxes as below -
image

I need to find which box are already checked here.
Here is the html code -

The active checkboxes has the class active as highlighted. How do I check this in katalon studio?
Please guide me.
HTML code -

<div class="md-scroll-mask" xpath="1">  <div class="md-scroll-mask-bar"></div></div>
<div class="_md md-open-menu-container md-whiteframe-z2 md-ams-intent-theme-theme md-active md-clickable" id="menu_container_11" aria-hidden="false" style="top: 8px; left: 649px; transform-origin: left top;" xpath="1"><md-menu-content width="4" class="metricSelection md-menu-bar-menu md-dense md-ams-intent-theme-theme" role="menu">
						<!-- ngRepeat: category in lgnd | filter:searchTerm --><md-menu-item ng-repeat="category in lgnd | filter:searchTerm" aria-label="category" ng-class="{'active': selectedCategory.indexOf(category) > -1}" class="md-in-menu-bar ng-scope active" style="">
							<button class="md-button md-ams-intent-theme-theme md-ink-ripple" type="button" ng-transclude="" md-prevent-menu-close="md-prevent-menu-close" ng-click="categoryTriggered(category)" aria-label="Spend" style="font-weight: normal !important" role="menuitem">
								Spend
							</button>
						</md-menu-item><!-- end ngRepeat: category in lgnd | filter:searchTerm --><md-menu-item ng-repeat="category in lgnd | filter:searchTerm" aria-label="category" ng-class="{'active': selectedCategory.indexOf(category) > -1}" class="md-in-menu-bar ng-scope active">
							<button class="md-button md-ams-intent-theme-theme md-ink-ripple" type="button" ng-transclude="" md-prevent-menu-close="md-prevent-menu-close" ng-click="categoryTriggered(category)" aria-label="Revenue" style="font-weight: normal !important" role="menuitem">
								Revenue
							</button>
						</md-menu-item><!-- end ngRepeat: category in lgnd | filter:searchTerm --><md-menu-item ng-repeat="category in lgnd | filter:searchTerm" aria-label="category" ng-class="{'active': selectedCategory.indexOf(category) > -1}" class="md-in-menu-bar ng-scope" style="">
							<button class="md-button md-ams-intent-theme-theme md-ink-ripple" type="button" ng-transclude="" md-prevent-menu-close="md-prevent-menu-close" ng-click="categoryTriggered(category)" aria-label="Orders" style="font-weight: normal !important" role="menuitem">
								Orders
							</button>
						</md-menu-item><!-- end ngRepeat: category in lgnd | filter:searchTerm --><md-menu-item ng-repeat="category in lgnd | filter:searchTerm" aria-label="category" ng-class="{'active': selectedCategory.indexOf(category) > -1}" class="md-in-menu-bar ng-scope">
							<button class="md-button md-ams-intent-theme-theme md-ink-ripple" type="button" ng-transclude="" md-prevent-menu-close="md-prevent-menu-close" ng-click="categoryTriggered(category)" aria-label="Conversions" style="font-weight: normal !important" role="menuitem">
								Conversions
							</button>
						</md-menu-item><!-- end ngRepeat: category in lgnd | filter:searchTerm --><md-menu-item ng-repeat="category in lgnd | filter:searchTerm" aria-label="category" ng-class="{'active': selectedCategory.indexOf(category) > -1}" class="md-in-menu-bar ng-scope">
							<button class="md-button md-ams-intent-theme-theme md-ink-ripple" type="button" ng-transclude="" md-prevent-menu-close="md-prevent-menu-close" ng-click="categoryTriggered(category)" aria-label="ROAS" style="font-weight: normal !important" role="menuitem">
								ROAS
							</button>
						</md-menu-item><!-- end ngRepeat: category in lgnd | filter:searchTerm --><md-menu-item ng-repeat="category in lgnd | filter:searchTerm" aria-label="category" ng-class="{'active': selectedCategory.indexOf(category) > -1}" class="md-in-menu-bar ng-scope active" style="">
							<button class="md-button md-ams-intent-theme-theme md-ink-ripple" type="button" ng-transclude="" md-prevent-menu-close="md-prevent-menu-close" ng-click="categoryTriggered(category)" aria-label="ACOS" style="font-weight: normal !important" role="menuitem">
								ACOS
							<div class="md-ripple-container" style=""></div></button>
						</md-menu-item><!-- end ngRepeat: category in lgnd | filter:searchTerm --><md-menu-item ng-repeat="category in lgnd | filter:searchTerm" aria-label="category" ng-class="{'active': selectedCategory.indexOf(category) > -1}" class="md-in-menu-bar ng-scope" style="">
							<button class="md-button md-ams-intent-theme-theme md-ink-ripple" type="button" ng-transclude="" md-prevent-menu-close="md-prevent-menu-close" ng-click="categoryTriggered(category)" aria-label="Impressions" style="font-weight: normal !important" role="menuitem">
								Impressions
							<div class="md-ripple-container" style=""></div></button>
						</md-menu-item><!-- end ngRepeat: category in lgnd | filter:searchTerm --><md-menu-item ng-repeat="category in lgnd | filter:searchTerm" aria-label="category" ng-class="{'active': selectedCategory.indexOf(category) > -1}" class="md-in-menu-bar ng-scope" style="">
							<button class="md-button md-ams-intent-theme-theme md-ink-ripple" type="button" ng-transclude="" md-prevent-menu-close="md-prevent-menu-close" ng-click="categoryTriggered(category)" aria-label="Clicks" style="font-weight: normal !important" role="menuitem">
								Clicks
							<div class="md-ripple-container" style=""></div></button>
						</md-menu-item><!-- end ngRepeat: category in lgnd | filter:searchTerm --><md-menu-item ng-repeat="category in lgnd | filter:searchTerm" aria-label="category" ng-class="{'active': selectedCategory.indexOf(category) > -1}" class="md-in-menu-bar ng-scope">
							<button class="md-button md-ams-intent-theme-theme md-ink-ripple" type="button" ng-transclude="" md-prevent-menu-close="md-prevent-menu-close" ng-click="categoryTriggered(category)" aria-label="CTR" style="font-weight: normal !important" role="menuitem">
								CTR
							</button>
						</md-menu-item><!-- end ngRepeat: category in lgnd | filter:searchTerm --><md-menu-item ng-repeat="category in lgnd | filter:searchTerm" aria-label="category" ng-class="{'active': selectedCategory.indexOf(category) > -1}" class="md-in-menu-bar ng-scope">
							<button class="md-button md-ams-intent-theme-theme md-ink-ripple" type="button" ng-transclude="" md-prevent-menu-close="md-prevent-menu-close" ng-click="categoryTriggered(category)" aria-label="Avg CPC" style="font-weight: normal !important" role="menuitem">
								Avg CPC
							</button>
						</md-menu-item><!-- end ngRepeat: category in lgnd | filter:searchTerm --><md-menu-item ng-repeat="category in lgnd | filter:searchTerm" aria-label="category" ng-class="{'active': selectedCategory.indexOf(category) > -1}" class="md-in-menu-bar ng-scope">
							<button class="md-button md-ams-intent-theme-theme md-ink-ripple" type="button" ng-transclude="" md-prevent-menu-close="md-prevent-menu-close" ng-click="categoryTriggered(category)" aria-label="Conv Rate" style="font-weight: normal !important" role="menuitem">
								Conv Rate
							</button>
						</md-menu-item><!-- end ngRepeat: category in lgnd | filter:searchTerm -->
					</md-menu-content></div>

@kazurayam can you please help me ?

I have similar problems and I use this kind of solutions (not tested):

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

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

import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

WebDriver driver = DriverFactory.getWebDriver()
‘To locate parent’
WebElement Element = driver.findElement(By.xpath(‘//div[@id=“menu_container_11”]/md-menu-content’))
‘To locate child of parent it will Capture all the childs available in the parent’
List childs = Element.findElements(By.tagName(‘md-menu-item’))
‘Childs in parent’
int child_count = childs.size()

for(int i = 1; i<=child_count; i++){

String classString = WebUI.getAttribute(byXpath(‘//div[@id=“menu_container_11”]/md-menu-content/md-menu-content[’ + i.toString() + ‘]’), “class”)

if(classString.contains(‘active’)){
WebUI.comment(WebUI.getAttribute(byXpath(‘//div[@id=“menu_container_11”]/md-menu-content/md-menu-content[’ + i.toString() + ‘]/button’), “aria-label”))
}
}

‘Create temporary object by xpath’
def byXpath(String objectId){
def myNewObject = new TestObject(objectId)
myNewObject.addProperty(“xpath”, ConditionType.EQUALS, objectId, true)
return myNewObject
}

1 Like

You can use one of these two APIs to read the class attribute.

1 Like