18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

How to know if a checkbox has been checked

LeoaLeoa Members
edited January 2013 in Sahi Pro
I'm current working on a Sahi script for a page that has one checkbox on it. I am using this script to evaluate if the checkbox has been checked:


_alert(_checkbox("just_listed").checked);// Before checkbox is checked. This should display false.
_check(_checkbox("just_listed"));// checkbox is checked
_alert(_checkbox("just_listed").checked);// After checkbox is checked. This should display true.
_assertFalse(_checkbox("just_listed").checked,"Just Listed box unchecked");//


Both alert functions display false. How do I get the check box to evaluate to true?

the page I'm testing is http://realestate.nj.com/for-rent

Best Answer

  • Yes slashes are important in this case, basically slashes are used here to identify the div with regular expression.
    Since div class is changing (depends upon checkbox), to get the div element uniquely, I used regular expression. You can also use some other API like _in, _near if you don't want to use the regular expression.

Answers

  • Hi,

    Actually the checkbox is not toggling due to its value, its toggling due to its background image.

    you can use the following code to verify that the checkbox is checked:

    _div("/cbjar/").className.indexOf("_active") != -1

    --
    Kshitij Gupta
  • LeoaLeoa Members
    Thanks! I'll try this.
  • LeoaLeoa Members
    Are the forward slashes important? Is there a reason why cbjar is not in quotes only: _div("cbjar")
  • LeoaLeoa Members
    Thanks, I was able to implement your code and it worked splendidly.
Sign In or Register to comment.