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.

Comparing the text in the drop down

maple24maple24 Members
edited November -1 in Sahi - Open Source
Hi ,

Is there any option in SAHI to compare a text in a drop down with any string using 'like'/'contains' or something like that.
I need this function to validate if the drop down values are populated correctly.

eg. It is expected that the drop down is populated with

-Select-
Long term care
Critical Illness
....
.....

instead of
-Select-
::INSURANCE_1::EN
::INSURANCE_2::EN
.....

If the drop down has '::INSURANCE_%' ,it is an issue and need to be fixed.
I know I can compare them with the list of correct values, but in few places the drop down values are dynamic and it very tedious to list the values for the entire application.

Thanks,

Comments

  • globalwormingglobalworming Moderators
    edited January 2012
    Hi maple24

    try something like _assertEqual("yourText", _select("identifier").options[$index].text) and loop through _select("identifier").options.length

    Regards
    Wormi
  • Hi Wormi,

    Thanks for your reply.
    I understand your solution , but in my case , the " your text" is not a entire text I am comparing.

    If you read my post again, you will understand.

    I am comparing 'abcde' with '%bc%'.

    Thanks again.
  • globalwormingglobalworming Moderators
    edited January 2012
    Well you got so many solutions, just have a look at http://sahi.co.in/w/browser-action-apis under the headline "assertions"

    try _assertContainsText or _assertTrue(_select("identifier").options[$index].text.match("Your Text"))
    the "match" solution should work with regular expressions, that may be usefull too,
  • Wow..thats exactly I am looking for. I can't believe I din't notice that being there.
    I guess _assertContainsText would work for me.Let me try.

    Once again thanks for your prompt reply.
  • No problem :)
    I hope it works. Just ask when you encounter further problems.
  • I tried to incorporate _assertContainsText , but it gives me error.

    Here is the code from script and the corresponding error:
    _assertContainsText ( /INSURANCE/,_getSelectedText(_select(0,_near( _cell("Product Type:")))),"LOCALIZATION ISSUE");
    

    The selected value in the drop down is " **INSURANCE_PRODUCT_TYPE_8:EN**"

    Am I missing anything with the syntax??

    Error I got on SAHI console is :

    TypeError: 'undefined' is null or not an object
    No trace available

    Any thoughts on this ?

    Thanks.
  • I solved the issue with the following changes in the script:
    var $a=/INSURANCE_PRODUCT/;
    
    var $b = _getText(_select(0,_near( _cell("Product Type:"))).options[$i]);  // $i is used within for loop 
    
    if (_assertContainsText ( $a,$val))
    
    {
    _writeToFile ("Localization Issue in the Insurance Product dropdown.","URL",true);
    $i=$val.length;
    }
    

    Hope this helps someone who is looking for a solution.

    Thanks.
This discussion has been closed.