How to identify Checkbox is checked or not

Hi,

I am using below javascript code to identify the checkbox is checked or not and taking output of it in one argument. But its not working.

document.querySelector("#pt1\:r1\:0\:rt\:1\:r2\:0\:dynamicRegion1\:0\:r1\:1\:AP1\:sbc32\:\:Label0").Checked

image

Is there any other way to achieve the same?
Thanks in Advance.

Hi,

if you are using Firefox or chrome browser you need to add return keyword at start.

Regards,
Amit

HI Amit,

As you suggested, i have added return keyword in the code as below and storing its output in one String type argument. Test run is getting successful but its not printing any output.-

return document.querySelector("#pt1\:r1\:0\:rt\:1\:r2\:0\:dynamicRegion1\:0\:r1\:1\:AP1\:sbc32\:\:Label0").checked;

I tried to use Boolean argument to store the output but its is giving below error-

Hi,

Use a string argument.

Regards,
Amit Anand

Hi Amit,

As I mentioned above, Since am getting error with Boolean type argument, I am using String argument only and process is giving test run successful but not getting any output.

  1. when checkbox is checked am getting blank output
  2. When checkbox is unchecked, still am getting blank output.

Hi,

Kindly check in browser developer console if the javascript code is identifying the web element correctly.

Regards,
Amit Anand

Hi Amit,

Javascript is able to identify the element but when I am using “.checked” method, is it saying undefined.
I tried to use control exist, get value actions as well. But nothing is working.

image

image

Is there any other way to achieve it?

Hi,

The check box that you showed in screenshot has it been defined as input type as check box. If yes, then checked function would have returned the correct output. Check and revert how that has been defined in HTML DOM structure.

image

Hi Amit,

Issue has been resolved. I am able to get the output by using .checked method in javascriot.
Thanks you for help :slight_smile: