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.

Unable to deal with dynamic number of radio buttons.

AkhilsAkhils Members
edited November -1 in Sahi - Open Source
To submit a form I need to select some radio buttons. The number of these radio buttons are dynamic in nature.



I am trying following codes:

for (var $i=0; $i<25; $i++)
{

if (_condition(_cell(_table("myTable1"), $i, 3) != 'Null'))
_click(_radio("tempP[$i]"));

else
$i=25;
}

Control is not transfering to else.
Any solution plz

Comments

  • Hi Akhil,

    Try if this works:
    for (var $i=0; $i<25; $i++)
    {
           
        if (_condition(_cell(_table("myTable1"), $i, 3) != Null))
            _click(_radio("tempP[" + $i + "]"));
        else
            $i=25;
    }
    
    Regards,
    Pankaj.
  • AkhilsAkhils Members
    Thanks Pankaj,

    I have tried that but its not working. I noticed only some changes in statment

    Previously:

    _click(_radio("tempP[0]"));
    saveCondition(_cell(_table("myTable1"), 1, 3) != 'Null');
    _click(_radio("tempP[1]"));
    _click(_radio("tempP[1]"));
    _click(_radio("tempP[1]"));
    _click(_radio("tempP[1]"));
    _click(_radio("tempP[1]"));
    --Stopped Playback: FAILURE--

    After modifying code:

    _click(_radio("tempP["+0+"]"));
    saveCondition(_cell(_table("myTable1"), 1, 3) != 'Null');
    _click(_radio("tempP["+1+"]"));
    _click(_radio("tempP["+1+"]"));
    _click(_radio("tempP["+1+"]"));
    _click(_radio("tempP["+1+"]"));
    _click(_radio("tempP["+1+"]"));
    --Stopped Playback: FAILURE--


    I think SAHI is unable to understand != 'Null'
  • narayannarayan Administrators
    Null is small case in javascript.
    Use
    for (var $i=0; $i<25; $i++){
        if (_condition(_cell(_table("myTable1"), $i, 3) != null)){
            _click(_radio("tempP[" + $i + "]"));
        } else {
           break;
        }
    }
    
    btw, I think you could also have just used:
    for (var $i=0; $i<25; $i++){
        if (_condition(_radio("tempP[" + $i + "]") != null)){
            _click(_radio("tempP[" + $i + "]"));
        } else {
            break;
        }
    }
    
  • AkhilsAkhils Members
    Thanks Naraynan, its working fine.
Sign In or Register to comment.