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.

drop down list selection

edited November -1 in Sahi - Open Source
Hi all
I have requirement to test the details of the members which are populated in the drop down list by selecting one by one since the number of drop down list is not fixed based on the logged in user i have counted the length but i don't know its not working... i am new to automation ..please help me on this


var $nItemsInDropdown
_set($nItemsInDropdown,_select(ddlUser).options.length);

for(var $y=0;$y<$nItemsInDropdown;$y++)
{

_click(_getSelectedText(_select("ddlUser").options[$y].value));

}

i am getting the below error

_sahi.setServerVar('\$nItemsInDropdown', _select(ddlUser).options.length);
TypeError: 'ddlUser' is undefined
No trace available

ddluser is the name of the drop down list.....

Comments

  • narayannarayan Administrators
    _select(ddlUser) should be
    _select("ddlUser") ?
  • Hi Narayan,
    Thanks for ur prompt reply..
    i have removed the quotes as u sad but still is not working the below is the modified code
    _click(_div("divFamilylock")); is used to open the drop down

    for(var $y=0;$y<(_select(ddlUser).options.length);$y++)
    {
    _click(_div("divFamilylock"));
    _click(_getSelectedText(_select(ddlUser).options[$y].value));

    }

    I see the below error in logs
    ERROR
    ReferenceError: "ddlUser" is not defined. at Mar 4, 2011 4:01:41 PM

    please correct me if i am wrong
  • Any suggestions...?
  • narayannarayan Administrators
    Use the quotes. They are required.
  • edited March 2011
    After using the quotes i got the below error and script was failed

    _click(_getSelectedText(_select("ddlUser").options[0].value));

    TypeError: 'options.length' is null or not an object
    No trace available

    In my application the Drop Down list items generated are dynamic and is loaded based on the logged in user
  • Can anyone help me on this i am stuck here....
  • Could you try _setSelected(_select("ddlUser"), _select("ddlUser").options[$y].text)
    It sets the value correct but it lacks the clicking... if the clicking is needed, I can't find a workaround right now
  • edited March 2011
    This is the modified code but still its not working
    Please excuse me if am wrong since i am very new to automation

    _click(_link("Claims Status"));
    var $nItemsInDropdown
    _set($nItemsInDropdown,_select(ddlUser).options.length);

    for(var $y=0;$y<$nItemsInDropdown;$y++)
    {
    _click(_div("divFamilylock"));
    _click(_setSelected(_select("ddlUser"), _select("ddlUser").options[$y].text));
    }

    yes i need clicking of each item in dropdown one by one..

    Thanks in advance
  • this should do it... i hope =)

    _click(_link("Claims Status"));
    var $nItemsInDropdown =_select(ddlUser);

    for(var $y=0;$y<$nItemsInDropdown.options.length;$y++)
    {
    _click(_div("divFamilylock"));
    _setSelected($nItemsInDropdown, $nItemsInDropdown.options[$y].text));
    }

    if not, please post the errors
  • Hi globalwarming thanks for looking into my issue
    i am getting the below error when i execute the above code

    ERROR
    ReferenceError: "ddlUser" is not defined. at Mar 8, 2011 4:08:33 PM

    Thanks in Advance
  • oh sorry , i forgot the quotes...

    change this line
    var $nItemsInDropdown =_select(ddlUser);
    to
    var $nItemsInDropdown =_select("ddlUser");
  • Hi globalworming

    The code which u gave is working fine without any errors but the problem is it is not selecting the values in drop down instead it skips and goes to next line.....
  • globalwormingglobalworming Moderators
    edited March 2011
    hmm maybe you could provide the URL where your script is running... because I have no further ideas how to solve this problem... am I right that the clicking is important? does the selectfield change to the values with this line:

    _setSelected($nItemsInDropdown, $nItemsInDropdown.options[$y].text));

    if yes, you could try to just add a

    _click($nItemsInDropdown) ;

    after this line so that it looks like


    _click(_link("Claims Status"));
    var $nItemsInDropdown =_select("ddlUser");
    for(var $y=0;$y<$nItemsInDropdown.options.length;$y++)
    {
    _click(_div("divFamilylock"));
    _setSelected($nItemsInDropdown, $nItemsInDropdown.options[$y].text));
    _click($nItemsInDropdown) ;
    }
  • narayannarayan Administrators
    Hi Prashanth and Wormi,

    You can select an option in a select box using index also.

    So you could have done:
    var $nItemsInDropdown = 0;
    _set($nItemsInDropdown,_select("ddlUser").options.length);
    for(var $y=0;$y<$nItemsInDropdown;$y++)
    {
       _setSelected(_select("ddlUser"), $y);
    }
    
  • thanks a lot narayan for u reply i am able to select the users from drop down..

    Any how sahi rocks.....
  • Nice and easy solution. I didn't know that you can set _select by giving a number. Thanks narayan, I will change that in my scripts =)
This discussion has been closed.