TestProject Forum

Working with checkbox element

I am creating a new test where I want to check a checkbox element (if it is not already checked).

Currently, I am using the ‘Click’ method which does not seem to be the most suitable since if the checkbox is already checked, clicking it again will make it unchecked!

Scenario 01:
1.1: Need to know the checkbox’s current state. If is unchecked (do not know how to do that)
1.2: Click on the element (in order to check it)

Scenario 02:
2.1: Use the ‘Check’ method (which should work regardless of the current checkbox element state). Does this method exist (check / uncheck method?)

Hello @sandro.pinto,

For checking a checkbox’s state and click on it only if it’s unchecked, you can create the following steps:

  • Hover the checkbox element, press double-shift on your keyboard to capture it, and use the “Get Attribute Value” action.

  • Set the AttributeName input field to “checked” which will indicate if the checkbox is checked or not. save the output value into a parameter (is_chceked) for further use.

(Notice: if the checkbox is checked, the “checked” attribute value will be “true” otherwise, the value will be an empty string)

image

  • Create a new step, that performs a “Click” action on that checkbox, add a condition to this step, the condition will validate the “is_checked” parameter value and will execute the “Click” step only if the “is_checked” parameter value is not empty.
  1. Click on the “Advanced Options”

image

  1. Scroll down to the “Conditions” section, set the parameter to “is_checked”, the condition to “Equals”, and leave the last field empty, so the condition will check whether the value is empty or not.

image

This way, the “Click” step will be executed only if the condition is met, otherwise, it will be skipped.
Using these two test steps, you can click on a checkbox only if it’s unchecked.

Hi @meidan.nasi thanks very much for your support.
This is exactly what I was looking for!