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.

only Unchecked options needs to selected

jeevithajeevitha Members
edited November -1 in Sahi - Open Source
Hi,

One of my requirement is to select all the 6 checkbox in the web page but defaultly 2 checkbox already selected.

can you help me for selecting only the unchecked option while automating using SAHI.

Comments

  • narayannarayan Administrators
    if (_condition(!_checkbox("xxx").checked)) {
       _click(_checkbox("xxx"));
    }
    

    If you want, you can add two new APIs to Sahi: _check and _uncheck. These APIs will only check if the element is not checked and vice versa.


    To enable these:

    1) Add this to the end of concat.js
    Sahi.prototype._check = function (el) {
        if (el.checked) return;
        this._click(el);
    }
    Sahi.prototype._uncheck = function (el) {
        if (!el.checked) return;
        this._click(el);
    }
    

    2) Add _check and _uncheck at the end of sahi/config/scheduler_functions.txt
    3) Make sure _check is not present in sahi/config/normal_functions.txt
    4) Restart Sahi.

    You can now use _check(_checkbox("xxx")) on all 6 checkboxes and it will only check the ones which are not already checked.

    I will be adding these APIs to the next version of Sahi.

    Regards,
    Narayan
  • Thanks a lot narayan! Able to automate successfully after adding these APIs.
  • nagarnagar Members
    edited October 2011
    Hi Narayan,

    I am using the same code lines, as described by you. These are:

    var $checkboxstr = $checkboxname + "[" + $index + "]";
    if (_condition(!_checkbox($checkboxstr).checked)) {
    _click(_checkbox($checkboxstr));
    }

    But when I run this code, it throws syntax error on conditional statement, "if(_condition(!_checkbox.......... "

    I can't understand, how this is syntactically wrong. Please help in this.
  • If anyone has any idea on my above mentioned issue then kindly help.
  • Hi nagar,


    Try with the following script,

    var $checkboxstr = $checkboxname + "[" + $index + "]";
    _check(_checkbox($checkboxstr));

    This might help you.

    Regards,
    Theeran.
  • nagarnagar Members
    edited October 2011
    Hi Theeran,

    I tried with your suggestion. But again I am getting syntax error on code line: "_check(_checkbox($checkboxstr));"


    Also, I have added these _check() and _uncheck() APIs in scheduler_function.txt, as suggested by Narayan.
  • Hi nagar,

    Can you please be more specific.

    Also, post the errors displayed on sahi console and url and the actual script.

    Regards,
    Theeran.
Sign In or Register to comment.