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 a drop down item which contains a substring

iscopiaiscopia Members
edited November -1 in Sahi - Open Source
Hello,

I would like to know how to select the first item in a drop down list which contains the supplied text.

for example...if my list box contains the following entries...

first entry
second entry
3rd entry
4th entry
5th entry

I would like to pass only the text "th" and have the value set to "4th entry".

Thanks,

Eric.

Comments

  • narayannarayan Administrators
    _setSelected(_select("id"), /th/) should work.
  • iscopiaiscopia Members
    Thanks for the help. Works fine for hard coded values.
    What if I want to pass the value in a variable?
    I've tried the following plus another couple of variants with no success.

    var $test = "th";
    _setSelected(_select("id"), /$test/)

    Thanks,

    Eric.
  • iscopiaiscopia Members
    Nevermind, figured it out...and also added the ability to remove any trailing spaces :-)

    var $test = "th";
    _setSelected(_select("country"),RegExp($test.replace(/\s+$/, '')));
This discussion has been closed.