How to select the Checkboxes when there are set of both Enable and Disabled checkboxes

Hi Creta,

I saw the images you have sent and I notice that the properties of the checkboxes are the same except for the disabled attribute. So try doing this. . .

  1. Create an object using the “type” attribute with a value of “checkbox”

  2. And then do this code:

//this line collects all the checkboxes, enabled and disabled
//make sure to use the object with the locator of "type"
java.util.List<WebElement> checkBox = WebUiCommonHelper.findElements(findTestObject("your_testobject_for_checkbox"), 30)

//checks if the checkbox is enabled then it will be clicked otherwise it will be ignored. . .
for (int index = 0; index <= checkBox.Size; index++)
{
     if (checkbox[index].getAttribute("disabled") != null)
     {
            // do nothing
     }
     else
     {
           checkbox[index].click()
     }
}

Hope that helps. . . :slight_smile:

Hi i tried the code given by you and i see some errors.Is it required to import any package?

:frowning: Actually i tried re writting the script given by you but error is same.

Did you run it?

Please provide error message. . . .

Saw it… its not webUI… its “WebUiCommonHelper”

Try it. . .

Here is the error.

Test Cases/Checkbox FAILED because (of) (Stack trace: groovy.lang.MissingPropertyException: No such property: WebUiCommonHelper for class: Script1552878904002
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at Script1552878904002.run(Script1552878904002.groovy:21)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:183)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:108)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:294)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:285)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:264)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:256)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:200)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:99)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:90)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)
at TempTestCase1552901873978.run(TempTestCase1552901873978.groovy:22)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
at groovy.lang.GroovyShell.run(GroovyShell.java:518)
at groovy.lang.GroovyShell.run(GroovyShell.java:507)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)
at groovy.ui.GroovyMain.run(GroovyMain.java:384)
at groovy.ui.GroovyMain.process(GroovyMain.java:370)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)
at groovy.ui.GroovyMain.main(GroovyMain.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)
)

Sorry. . . Try making the first letter of “Size” into small letter “s”.

like this: checkbox.size()

and also. . . . the java variable names are case sensitive, so could you rename your “checkbox” to “checkBox”

I think it will now work…

Also,

Kindly change the condition from “==” to “!=”

Try it

good luck to you :smile:

Hey i see there is no error in the script now but when i ran the test case it showed me this error

Here is the Log view

did you perform that step?

yes

Did you also changed the if condition to this?

java.util.List checkBox = WebUiCommonHelper.findWebElements(findTestObject(‘New changes/Customer/Check’), 30)

for (int index = 0; index <= checkBox.size; index++)
{
if (checkBox[index].getAttribute(“disabled”) != null)
{

 }
 else
 {
	   checkBox[index].click()
 }

}