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.

identifier functions in Sahi script

sterry1sterry1 Members
edited November -1 in Sahi - Open Source
I am exploring Sahi and would like to know how to extend Sahi script. We have an application that changes the ids of UI elements on a page when design changes are made. Here is an example

<input id="mx726" ctype="textbox" li="mx727" type="text" class="text ib" value="" title="WO Description"/>

The id might change to "mx678" for this text input box however the title rarely changes. I have looked thru the apis but it is unclear to me how to extend the Sahi script functions to include identifiers by title. Would someone offer some suggestions to get started? Thanks from a Sahi newbie.

Comments

  • narayannarayan Administrators
    Hi sterry1,

    There are various attributes by which Sahi identifies elements. The first default for most elements is id. But if you look at the Alternatives dropdown on the Controller, you will see the various other identifiers for the same element.

    If you want to prevent ids from being used as default, Sahi allows a way to ignore specific ids which may match a pattern.

    Open sahi/htdocs/spr/concat.js

    Search for isIgnorableId. You will see a function like this:
    Sahi.prototype.isIgnorableId = function(id){
        // zkoss, extjs, xilinus, gmail
        return id.match(/^z_/) || id.match(/^j_id/) || id.match(/^ext[-]gen/) || id.match(/^[:]/) || id.match(/^zk_comp_/);
        //  || id.match(/_[0-9]{10,}_/);
    };
    

    Add your own expression to the list of regular expressions. Eg. if you want to ignore ids which start with mx, then add id.match(/^mx/) so that your function now looks like:
    Sahi.prototype.isIgnorableId = function(id){
        // zkoss, extjs, xilinus, gmail
        return id.match(/^z_/) || id.match(/^j_id/) || id.match(/^ext[-]gen/) || id.match(/^[:]/) || id.match(/^zk_comp_/) || id.match(/^mx/);
        //  || id.match(/_[0-9]{10,}_/);
    };
    

    Restart Sahi, clear browser cache and Sahi will ignore ids which start with mx.

    Regards,
    Narayan
  • sterry1sterry1 Members
    thanks narayan, your answer was most helpful. Sahi is very impressive. I have been using Selenium and WebDriver for some time now to do Web testing on our enterprise applications but Sahi promises to make this work a breeze.
  • narayannarayan Administrators
    Thanks for the appreciation :)
Sign In or Register to comment.