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.

what does _byText do?

keatskeats Members
edited November -1 in Sahi - Open Source
what does _byText do?

I was trying to use that as
_byText("some text found in table first row","<td>");
it shows null..


any help.
Tagged:

Comments

  • keatskeats Members
    hi Narayan,

    Can i access any tags by its class name instead of id?
    for example:
    <td id="descId" class="formTxt>
    _cell("descId")- This syntax is for row id.

    Is there a way to access html element by its class name.

    Let me know please.
  • narayannarayan Administrators
    Use _byText("some text found in table first row","td"); for the first case.
    In fact you can use _cell("some text found in table first row") if that is what you want.
  • keatskeats Members
    Ok. So can i access any html element by its class name?
  • narayannarayan Administrators
    Not really, _byText uses visible text, not tag attributes. Currently you will have to write a custom function to access an element by tag and className.

    Add this to the end of sahi/htdocs/spr/concat.js
    Sahi.prototype._byClassName = function (className, tagName) {
        var res = this.getBlankResult();
        var el = this.findTagHelper(className, this.top(), tagName, res, "className").element;
        return el;
    };
    

    Open sahi/config/normal_functions.txt and add _byClassName at the end of it.

    Restart Sahi and you can use _byClassName("formTxt", "td");

    Let me know if that works for you and I will add it to the next build.
  • keatskeats Members
    Yes Narayan, It works. I tried to click a button by accessing the class and it works perfectly fine.
    _click(_byClassName("sysButn","input"));

    Thanks.
This discussion has been closed.