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.

Selecting values IF they exist

vt_hokie2008vt_hokie2008 Members
edited November -1 in Sahi - Open Source
My situation is I have a drop down list and I want to select either A, B, or C from the list IF it exists in the list. How can I go about doing this? Only one of them will be in the list at a time, but whether it is there or not depends on what you select in another drop down list above this one in the form.

Comments

  • edited November 2011
    You can try to save the value of what is in the list first into a var, and then select that var after using your if statement.
  • Hi vt_hokie2008,

    Try the following Script,
    var $a=new Array();
    $a=["A","B","C"];
    var $b=_getText(SelectElement);
    for(var $j=0;$j<$a.length;$j++){
        for(var $i=0;$i<$b.length;$i++){
            if($a[$j]==(_getText(SelectElement).options[$i]))){
                _setSelected(SelectElement,$a[$j]);
            }
        }
    }
    

    let us know,if the problem persists.

    Regards
    Theeran.
Sign In or Register to comment.