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 find element with the custom attributes?

SaiPradeepSaiPradeep Members
edited August 2013 in Sahi - Open Source
hi Pratyush,
I just tried with the steps mentioned in tweaking sahi APIS
this.addAD({tag: "INPUT", type: "text", event:"change", name: "_hiddencontrolid", attributes: ["hiddencontrolid","name", "id", "index", "className"], action: "_setValue", value: "value"});

when I hover over the element it identifies like _hiddencontrolid("id") butnot with the custom attribute:
like _hiddencontrolid("hiddencontrolid").

Kindly please help me out how to achieve this in Sahi Open source.

Thanks,
Sai Pradeep.

Best Answer

  • edited August 2013 Answer ✓
    Hi SaiPradeep,
    Sahi OS does not support custom attributes as of now. It will be available in the next released Sahi OS version.

    However, please follow these steps to get the desired functionality.

    1) open <path_to_sahi>\htdocs\spr\concat.js.
    2) search for this string in the file:
    Sahi.prototype.getAttribute =
    3) You will come across the getAttribute function.
    4) Replace that entire function with the following function:

    Sahi.prototype.getAttribute = function (el, attr){
    if (attr == null) return null;
    if (typeof attr == "function"){
    return attr(el);
    }
    if (attr.indexOf("|") != -1){
    var attrs = attr.split("|");
    for (var i=0; i<attrs.length; i++){
    var v = this.getAttribute(el, attrs);
    if (v != null && v != "") return v;
    }
    }else{
    if (attr == "sahiText") {
    return this._getText(el);
    }
    if (el[attr] != null) return el[attr]
    return el[attr] || el.getAttribute(attr);
    }
    };

    5) Now, search for the following string in the file:
    Sahi.prototype.areEqual2 =

    6) You will come across the areEqual2 function.

    7) Replace that entire function with the following function:

    Sahi.prototype.areEqual2 = function (el, param, value) {
    if (param == "sahiText") {
    var str = this._getTextNoTrim(el);
    if (value instanceof RegExp){
    str = this.trim(str);
    return str != null && str.match(value) != null;
    }
    if (str.length - value.length > 1000) return false;
    return (this.trim(str) == this.trim(value));
    }
    else {
    return this.areEqualParams(this.getAttribute(el, param), value);
    }
    };

    8) Save concat.js

    9) Note: the changes that you have made in prepareADs function are correct ie:

    this.addAD({tag: "INPUT", type: "text", event:"change", name: "_hiddencontrolid", attributes: ["hiddencontrolid","name", "id", "index", "className"], action: "_setValue", value: "value"});

    10) Restart Sahi and try to identify again.

    Your custom attribute should now get identified.
    If there is still any problem please let me know.

    Regards,
    Pratyush
Sign In or Register to comment.