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.

Verification of data in a drop down list

garimagarima Members
edited November -1 in Sahi - Open Source
I hace to record a web page where several drop down list are provided.
User needs to choose the required data from those drop downs.
How do I verify the data in these drop downs ?

Comments

  • gaveyomgaveyom Members
    edited October 2011
    Hi Garima,

    hope the below script will be useful to you, please try this script

    do let me know if u still facing any issue


    ******************************************************************************

    var $arry_Dropdown = [];
    var $val = _getText(_select("drpyear")); //drpyear is dropdown name/ id
    var $match_Val = "2003-04";
    for(var $i=0; $i<$val.length; $i++) {

    _set($arry_Dropdown[$i], _getText(_select("drpyear").options[$i]));

    if($arry_Dropdown[$i] == $match_Val) {

    _setSelected(_select("drpyear"), $match_Val);
    $i = $val.length;
    }

    }

    ******************************************************************************
  • I am trying to verify the options in a drop down by using a for loop

    for(var $i = 0; $i<_select("ctl00_cpRoot_ddlTargetAudience").length; $i++)
    {
    _alert(_getText(_select("ctl00_cpRoot_ddlTargetAudience").options[$i]));
    }

    but I guess the loop is not getting executed.

    Please help


    Thanks in advance
    Jasmine
  • Hi Jasmine,

    You can compare the options in the dropdown list using array.

    Here is an example:
    _navigateTo("http://sahi.co.in/demo/selectTest.htm");
    var $text=_getText(_select("s3Id"));
    var $textArray = new Array();
    _assertEqual($text, ["","o1","o2","o3","With spaces","With nbsp"]);
    

    You can also use for loop:
    _navigateTo("http://sahi.co.in/demo/selectTest.htm");
    var $text=_getText(_select("s3Id"));
    var $textArray = new Array();
    for(var $i=0; $i<$text.length; $i++)
    {
    _assertEqual($text, ["","o1","o2","o3","With spaces","With nbsp"]);
    }
    

    Let me know if you face any problem.

    Regards
    Sumitra
Sign In or Register to comment.