Article Overview:
This article will cover how you can achieve the following:
How to assert if a checkbox button in a page is unchecked or checked.
Problem Statement:
In certain scenarios, you need to verify whether a checkbox on a webpage is checked or unchecked before proceeding with test execution. Ensuring the correct state of the checkbox is essential for validating user interactions or default settings in automated testing.
Solution:
-
Store Element Details:
- Capture the details of the checkbox element using the
Store element details
command. This will store the properties of the element in a variable.Store element details of "Sample Data" in $checkbox
- Capture the details of the checkbox element using the
-
Check the "Checked" Property:
- Once the element is checked or unchecked, the property named "checked" changes its value.
- To verify if the element is unchecked, check if the "checked" property is set to
false
.
-
Perform Assertion:
- Validate the state of the checkbox by performing an assert:
Assert {$checkbox.checked == false} equals "True"
- Validate the state of the checkbox by performing an assert:
Examples:
The above-illustrated method demonstrated shows how the "checked" property is initially set to false, and after the checkbox is clicked, it changes to true. The assertion confirms whether the checkbox remains unchecked by verifying that the "checked" property is false.
Comments
0 comments
Please sign in to leave a comment.