Forum Discussion

Amna's avatar
Amna
Occasional Contributor
4 years ago

How to check the state of the checkbox?

In my test script there is a screen from which I have to check that either the checkbox is being checked or unchecked . If the checkbox state is checked then it should display the message that state is enabled otherwise checkbox have to be select through test script

 

See attached image for reference

  • Sorry but this is not clear for me.

     

    You want to examine the value of a checkbox

    And if the value is checked (true) then allow user to change the value.

     

    That's what you need ?

     

    To ask user to set a value you can use (quick and dirty code) :

    let checkboxValue = myWebObject.checked;
    if (checkboxValue) {
      let result = MessageDlg("Choose value of the checkbox by hitting the Yes for true or No for False", mtConfirmation, MkSet(mbYes, mbNo), 0);
      myWebObject.checked = result == mrYes;
    }

     

     

     

4 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Examine this web element in the Object Browser and figure-out what property indicates the state.

    This is because web page developers can use different web elements and techniques to output something that is rendered as a check-box.

     

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Thanks Alex!

       

       

      Hi Amna ! Does this advice help?

      • Amna's avatar
        Amna
        Occasional Contributor

        Actually what I want that if the checkboxes already checked then we can display the message the its already checked you can modify your selection something like that