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.

How to select values randomly in combo box

SelviSelvi Members
edited November -1 in Sahi - Open Source
Hi All,

I need to select value from combo box and want to delete it in SAHI. When i execute the next time i want to select a different value from combo box. Is it possible?

Any one help me with code or some idea regarding this...


Thanks in advance...

Kind regards,
Selvi

Comments

  • narayannarayan Administrators
    You can select using the index also.
    _setSelected(_select("selId"), 1); will choose 2nd option. (indexing starts from 0.)
  • Hi,

    I am trying to assert a value in a combo box, but it is showing me error.
    The assert statement is
    _assertExists(_option(_select("FSCList"), "testitem"));

    When i am running the script it is always failing, the log shows as follows

    _assertExists(_option(_select("FSCList"), "testitem"));
    TypeError: id.match is not a function
    http://s-ws.geodesic.net/_s_/spr/concat.js:2079
    http://s-ws.geodesic.net/_s_/spr/concat.js:2234
    http://s-ws.geodesic.net/_s_/spr/concat.js:3951

    How do i write the code for asserting an item in a combo box?

    Regards,
    Anoop
  • Hi Anoop

    I just googled an combobox example http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ComboBox/ComboBox.aspx and teh Sahi controller let's me select the entries without problemes, so using
    _assertExists(_listitem("testitem"))
    
    should be enough.

    Regards
    Wormi
  • The accessor is _select("FSCList") which is a combo box.
    It has multiple list items where as one item in the list is "testitem"

    I tried the code u gave in this way it is not working
    _assertExists(_select("FSCList")("testitem"));

    If i do a select operation in the list, it is working fine. The code is:
    _setSelected(_select("FSCList"), "testitem");
    this is executing properly in playback.

    But i'm not able to assert an item for existence or nonexistence, script always fails
    _assertExists(_option(_select("FSCList"), "testitem"));
    _assertNotExists(_option(_select("FSCList"), "testitem"));

    I'm not sure whether it is because of the wrong usage of _option api.

    I saw the post abt the same problem.. however it doesn't work for me..
    http://sahi.co.in/forums/viewtopic.php?id=2610

    Regards,
    Anoop
  • Hi Anoop,

    You could try this
    _assertExists(_option("testitem", _in(_select("FSCList"))));
    

    Regards,
    dkulkarni
  • Hi dkulkarni,

    I tried it. Its working perfectly!
    Thanks a lot.
    But i'm wondering why it is not working with the code i used even though it was the way described in tutorials and other forum posts. So i think i need to use _in api for all list assersions, isn't it? or it is specific to the type of combobox where i was testing?

    Regards,
    Anoop
  • Hi Anoop,

    Your usage was basically incorrect.

    If you want to assert that element exists on the page, then you can use

    _assertExists(_option("testitem"));

    However, if you wish to assert that element exists on the page AND inside the dropdown, use

    _assertExists(_option("testitem", _in(_select("FSCList"))));

    Regards,
    dkulkarni
  • Thanks for the confirmation. Its working.
This discussion has been closed.