Skip to content
CodeKruPro

Select a checkbox and verify its state

Automation taskEasyAsked in: Accenture, Capgemini

"How do you tick a checkbox only if it is not already ticked?" Check the selected state first, click only when needed, then check again. A click toggles the box, so clicking blindly can untick it.

Handle Checkboxes - Click and Verify

Handle Checkboxes

Use click() to toggle a checkbox and isSelected() to verify its state.

On the Checkboxes page, the single-select checkbox id="firstSelect1" is initially unchecked.

Task:

  1. Navigate to https://testkru.com/Elements/Checkboxes
  2. Find checkbox firstSelect1
  3. Print its state (should be false)
  4. Click it to select it
  5. Print its state (should be true)

Expected output:

Before click: false
After click: true
Read full tutorial on Codekru