I am not able to uncheck multiple checkbox of my application

Here is the script I am using to uncheck the checked checkboxes.

List elements = WebUiCommonHelper.findWebElements(findTestObject(‘Object Repository/Page_Dashboard/Dasboard_Report_stat_checkbox’), 30)

// Click each element
for (WebElement element : elements) {
WebUI.waitForElementClickable(element, 10)
try {
element.click()
} catch (Exception e) {
// Fallback to JavaScript click if the regular click fails
WebUI.executeJavaScript(“arguments[0].click();”, Arrays.asList(element))
}
}

2 Likes

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

Perhaps you could insert a count of elements that you “captured” and see if you have what you think you should have, or perhaps your TestObject has too specific a pathway. This will tell you if your concern is in your collection or in your loop.
Note I removed the “e” from your Exception since you did not use it.

List<WebElement> elements = WebUiCommonHelper.findWebElements(findTestObject('Object Repository/Page_Dashboard/Dasboard_Report_stat_checkbox'), 30)

WebUI.comment("we have ${elements.size()} elements")
// Click each element
for (WebElement element : elements) {
    WebUI.waitForElementClickable(element, 10)
    try {
        element.click();
    } catch (Exception) {
        // Fallback to JavaScript click if the regular click fails
        WebUI.executeJavaScript("arguments[0].click();", Arrays.asList(element))
    }
}

p.s. put three backticks on a line above your code, like ```, and three backticks on a line below your code so the code is more readable.

2 Likes

@sandeep.sharma , Please try the suggestion from @grylion54 and verify if it works. Let us know if you need further support. Thank you

@Elly_Tran @grylion54 I am still not able to click with the above script. Here is the console log I got on running the script.

2024-05-28 10:59:32.942 DEBUG  as per the selection on configure Stats - 1: openBrowser("")
2024-05-28 10:59:33.507 INFO  c.k.k.core.webui.driver.DriverFactory    - Starting 'Chrome' driver
May 28, 2024 10:59:33 AM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
2024-05-28 10:59:33.597 INFO  c.k.k.core.webui.driver.DriverFactory    - Action delay is set to 0 milliseconds
Starting ChromeDriver 124.0.6367.207 (a9001a6e39fbaa559510ca866052950457dd4e6b-refs/branch-heads/6367_201@{#3}) on port 11901
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1716874177.001][WARNING]: This version of ChromeDriver has not been tested with Chrome version 125.
May 28, 2024 10:59:37 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
2024-05-28 10:59:37.273 INFO  c.k.k.core.webui.driver.DriverFactory    - sessionId = a91eca446916d37c55f2f3022ab60e59
2024-05-28 10:59:37.304 INFO  c.k.k.core.webui.driver.DriverFactory    - browser = Chrome 125.0.0.0
2024-05-28 10:59:37.305 INFO  c.k.k.core.webui.driver.DriverFactory    - platform = Windows 10
2024-05-28 10:59:37.306 INFO  c.k.k.core.webui.driver.DriverFactory    - seleniumVersion = 3.141.59
2024-05-28 10:59:37.309 INFO  c.k.k.core.webui.driver.DriverFactory    - proxyInformation = ProxyInformation { proxyOption=NO_PROXY, proxyServerType=HTTP, username=, password=********, proxyServerAddress=, proxyServerPort=0, executionList="", isApplyToDesiredCapabilities=true }
2024-05-28 10:59:37.350 DEBUG  as per the selection on configure Stats - 2: navigateToUrl("/#/login")
2024-05-28 10:59:49.844 DEBUG  as per the selection on configure Stats - 3: setText(findTestObject("Page_Login/input_USERNAME_userName"), "test")
2024-05-28 10:59:52.123 DEBUG  as per the selection on configure Stats - 4: setEncryptedText(findTestObject("Page_Login/input_PASSWORD_password"), "test")
2024-05-28 10:59:53.056 DEBUG  as per the selection on configure Stats - 5: sendKeys(findTestObject("Page_Login/input_PASSWORD_password"), Keys.chord(ENTER))
2024-05-28 10:59:53.861 DEBUG  as per the selection on configure Stats - 6: click(findTestObject("Object Repository/Page_Dashboard/Dropdown_dashboard_stat"))
2024-05-28 11:00:03.704 DEBUG  as per the selection on configure Stats - 7: click(findTestObject("Object Repository/Page_Dashboard/a_Configure Stats"))
2024-05-28 11:00:05.095 DEBUG  as per the selection on configure Stats - 8: elements = findWebElements(findTestObject("Object Repository/Page_Dashboard/Dasboard_Report_stat_checkbox"), 30)
2024-05-28 11:00:09.364 DEBUG  as per the selection on configure Stats - 9: comment(we have $elements.size() elements)
2024-05-28 11:00:09.494 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - we have 3 elements
2024-05-28 11:00:09.495 DEBUG  as per the selection on configure Stats - 10: for (org.openqa.selenium.WebElement element : elements)
2024-05-28 11:00:09.498 DEBUG  as per the selection on configure Stats - 1: waitForElementClickable(element, 10)
2024-05-28 11:00:09.618 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/Frontend/Dashboard/Verify that the Reports section displays the reports as per the selection on configure Stats FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.waitForElementClickable() is applicable for argument types: (org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement, java.lang.Integer) values: [[[CChromeDriver: chrome on WINDOWS (a91eca446916d37c55f2f3022ab60e59)] -> xpath: //input[@type='checkbox' and @checked]], ...]
Possible solutions: waitForElementClickable(com.kms.katalon.core.testobject.TestObject, int), waitForElementClickable(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling), waitForElementNotClickable(com.kms.katalon.core.testobject.TestObject, int), waitForElementNotClickable(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling)
	at Verify that the Reports section displays the reports as per the selection on configure Stats.run(Verify that the Reports section displays the reports as per the selection on configure Stats:76)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1716874166447.run(TempTestCase1716874166447.groovy:25)

2024-05-28 11:00:09.961 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/Frontend/Dashboard/Verify that the Reports section displays the reports as per the selection on configure Stats FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.waitForElementClickable() is applicable for argument types: (org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement, java.lang.Integer) values: [[[CChromeDriver: chrome on WINDOWS (a91eca446916d37c55f2f3022ab60e59)] -> xpath: //input[@type='checkbox' and @checked]], ...]
Possible solutions: waitForElementClickable(com.kms.katalon.core.testobject.TestObject, int), waitForElementClickable(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling), waitForElementNotClickable(com.kms.katalon.core.testobject.TestObject, int), waitForElementNotClickable(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling)
	at Verify that the Reports section displays the reports as per the selection on configure Stats.run(Verify that the Reports section displays the reports as per the selection on configure Stats:76)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1716874166447.run(TempTestCase1716874166447.groovy:25)```

The above error means for the method, waitForElementClickable, you either have the wrong number of parameters, or you have the wrong data type for the parameters. It should look like:

WebUI.waitForElementClickable(findTestObject(...), 10)

In your code below, you have a WebElement instead of a TestObject used in the method (wrong data type). Either look up a Selenium “wait” statement for your WebElement or you need to convert a WebElement to a TestObject (or at least use the pathway of the WebElement to create a new TestObject).

for (WebElement element : elements) {
    // 'element' needs to become a TestObject
    WebUI.waitForElementClickable(**element**, 10)   

Edit: KS now has a method to do the conversion:

So, you could use the method like:
WebUI.waitForElementClickable(WebUI.convertWebElementToTestObject(element), 10)

@grylion54 I tried the same suggested above but didn’t work for me.

List elements = WebUiCommonHelper.findWebElements(findTestObject(‘Object Repository/Page_Dashboard/Dasboard_Report_stat_checkbox’), 30)

WebUI.comment(“we have ${elements.size()} elements”)
// Click each element
for (WebElement element : elements) {

WebUI.waitForElementClickable(WebUI.convertWebElementToTestObject(element), 10)

element.click()

}

it still shows error in console - element not interactable.

In my scenario, I have 10 checkboxes, and out of 10, there are some selected/checked checkboxes. I get the locators of checked/selected checkboxes and now I have to click on each selected/checked checkbox to unselect/uncheck them.

Unfortunately, without the HTML we may not be able to give you an exact cause of this error, but you can look up on this forum about “element not interactable” and see there are several resolutions that you can try on your own.
One of the reason the “element is not interactable” is because you do not have the authority for the page. You obviously can figure that one out. If you can do it manually, you have authority.
Another reason is the click statement is “not the method” to use; for this you can try enhancedClick or use javascript to click on the checkbox. Again, without the HTML for us to see, I will have to let you investigate.
Edit: is it your first item that is not interactable or is it further down the list in which it may be out of viewport? You may have to scrollToElement to keep the viewport on your objects.

for (WebElement element : elements) {
    if (!WebUI.verifyElementInViewport(WebUI.convertWebElementToTestObject(element), 10)) {
        WebUI.scrollToPosition(100, element.getLocation().getY() - 50)
    }
    WebUI.waitForElementClickable(WebUI.convertWebElementToTestObject(element), 10)
    // if element is checked then uncheck it
    if (element.isChecked()) {
        element.click()
    }
}

@sandeep.sharma

The log tells us that you have the Chrome browser of v125, and the Chrome Driver of v124. A slight difference. Any mismatch of browser’s and driver’s versions could cause variety of unpredictable errors that are hard to diagnoze. You should fix the mismatch first.

The Chrome Driver of v125 is already available. So you should update the Chrome Driver by
https://katalon-studio-8-x--docs-production-katalon.netlify.app/docs/create-tests/manage-projects/set-up-projects/web-testing/handle-webdrivers/upgrade-or-downgrade-webdrivers-in-katalon-studio

1 Like