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.

sahi not holding jquery objects

dkdk Members
edited November -1 in Sahi - Open Source
hi ,

I tried to use jQuery to retrieve elements , stored them into an array and again used jquery (OR sahi script) to get values of objects in that array. Sahi shows length of array correctly, but when I tried to retrieve each object in that array, I get null object.


var $sCount = new Array();
_set($sCount,$("#divArea").children().children(".spanchildclass"));


_alert($sCount.length); //here I get correct count of objects

for(var $i=0; $i< $sCount.length; $i++ ) {
var $sText;
_set($sText, $($sCount[$i]).text()); //each object in that array shows as null.
_alert($sText);
}


How can I make it work?

Thanks

Comments

  • narayannarayan Administrators
    Hi dk,

    Sahi will not be able to store DOM objects like that (Sahi serializes the object and sends it to the proxy. This won't work for DOM objects). I would suggest you build a browser function to get all the text in an array, and then use it.
    <browser>
    function collectText(){
        var els = $("#divArea").children().children(".spanchildclass");
        var textAr = [];
        for(var i=0; i< els.length; i++ ) {
            textAr.push(els[i].text());    //each object in that array shows as null.
        }
        return textAr;
    }
    <browser>
    
    
    var $textAr = [];
    _set($textAr, collectText());
    
    for (var $i=0; $i<$textAr.length; $i++) {
        _alert($textAr[$i]);
    }
    

    Regards,
    Narayan
  • dkdk Members
    Amazing!!
    Thanks a lot Narayan. I will try this.
  • dkdk Members
    Hi Narayan,
    I couldnt make this work.array returned null. So I tried, _set($sCount,$("#divArea").children().children(".spanchildclass").text()); which in turns returned correct texts, but without a delimiter. I have an alternate solution with javascript, for the time being I am using it .
    Thank you very much for looking into this.
Sign In or Register to comment.