Katalon doesn't see that the checkbox in the application is checked

Hello,
I have a problem with VerifyElementChecked /VerifyElementNotChecked.
In the mobile app I have the checkboxes checked, but object attributes have checked=false. What could be the reason for this and is there any other way to check if the checkboxes are checked?

@marysia9622 It might be that the object that gets the correct checked value is actually a parent, child or sibling object. Are you able to look through the object spy to see if it is a different object that sees the correct checked value?

I checked all objects, it is always checked=false.

To resolve the issue where Katalon does not recognize the checkbox state in your mobile app, follow these structured solutions:

1. Identify the Correct Attribute or Element

Inspect the Checkbox Properties

  • Use Katalon Spy or Appium Inspector to check all attributes of the checkbox element when it is checked/unchecked.
  • Look for attributes like checked, selected, value, enabled, or custom properties (e.g., aria-checked, isChecked).

Example:

If the checkbox uses aria-checked="true" when checked:

Mobile.verifyElementAttributeValue(findTestObject('Checkbox'), 'aria-checked', 'true', 10)

2. Use XPath to Target Dynamic States

If the checkbox state is reflected in nested elements or attributes, create an XPath locator.

Example:

// Check if a child element (e.g., an "checked" icon) exists when the checkbox is selected
TestObject checkedCheckbox = findTestObject('Checkbox')
checkedCheckbox.xpath = "//android.widget.CheckBox[@resource-id='your_id']/android.widget.ImageView[@checked='true']"
Mobile.verifyElementVisible(checkedCheckbox, 10)

3. Mobile-Specific Keywords

Use mobile-focused keywords to retrieve attributes or states.

Check selected Attribute:

boolean isChecked = Mobile.getAttribute(findTestObject('Checkbox'), 'selected', 10)
assert isChecked == true

Get Text or Content Description:

If the checkbox state is tied to text (e.g., “Checked”):

String text = Mobile.getText(findTestObject('Checkbox'), 10)
assert text.contains("Checked")

4. Custom Script Execution

Execute platform-specific native scripts to check the checkbox state.

Android (Espresso):

import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory

def driver = MobileDriverFactory.getDriver()
def checkbox = driver.findElement(By.id('your_checkbox_id'))
boolean isChecked = checkbox.getAttribute("checked").equals("true")
assert isChecked == true

iOS (XCUITest):

def driver = MobileDriverFactory.getDriver()
def checkbox = driver.findElement(By.id('your_checkbox_id'))
boolean isChecked = (checkbox.getAttribute("value") == "1")
assert isChecked == true

5. Image Recognition (Last Resort)

Use Katalon’s built-in image verification if the checkbox has a unique visual indicator.

Mobile.verifyImagePresent('checked_checkbox_image.png', 10)

6. Wait for State Stabilization

Ensure the element is fully rendered before verification:

Mobile.waitForElementPresent(findTestObject('Checkbox'), 10)
Mobile.verifyElementChecked(findTestObject('Checkbox'), 10)

Why This Happens

  • Custom UI Components: The app may use non-standard controls that don’t update standard attributes like checked.

  • Timing Issues: The UI might not have finished updating when the verification occurs.

  • Platform Differences: Android/iOS may handle checkbox states differently (e.g., checked vs. selected).

  • Avoid Hardcoding: Use dynamic XPath/CSS selectors to adapt to UI changes.

  • Cross-Platform Checks: Handle Android and iOS separately if needed.

  • Logging: Add debug logs to track the actual attribute values during test execution.

By targeting the correct attributes or leveraging mobile automation frameworks, you can reliably verify checkbox states even with custom UI implementations.