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 can I compare with _contain API ?

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

I am using the following code and I wish to compare both values so can you tell guide me in this issue ?

ex:- (Parent is array, child is string)
var $txtBoxes = _collect("_textbox", "/txt/", _in(_table(22)));
var $xx = new Array();

for ( var $i = 0; $i < $txtBoxes.length; $i++) {
    var $Attr_Name = _getText($txtBoxes[$i]);
    //_debug($Attr_Name);
    $xx[$i] = $Attr_Name;
    //_assertEqual($Attr_Name, "Col_Name1", "Pass");

}

_click(_button("Submit"));
_click(_button("Submit"));
var $yy = new Array();
var $links = _collect("_link", "/./", _in(_row(48)));
for ( var $i = 0; $i < $links.length; $i++) {
    var $link_Name = _getText($links[$i]);
    //_debug($link_Name);
    var $Col_Name = $link_Name;
    $yy[$i] = $Col_Name;

}

for ($j = 0; $j < $xx.length; $j++) {
    var $Attr_Name = $xx[$j];
    _debug($Attr_Name);
    _debug(_contains($yy, $Attr_Name));

}

Comments

  • Hi kplokesh,

    Use:
    Array.prototype.contains = function(k) {
        for(p in this){
            if(this[p] === k)
                return true;
        return false;
       }
    }
    
    

    You can then call the contains method like this:
    for ($j = 0; $j < $xx.length; $j++) {
        var $Attr_Name = $xx[$j];
        _debug($Attr_Name);
        _debug($yy.contains($Attr_Name));
    }
    

    Regards,
    dkulkarni
Sign In or Register to comment.