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.

value of variable not as expected

technoleftytechnolefty Members
edited November -1 in Sahi - Open Source
Sahi
Version : V3.5
Build : 2011-05-25 (change log)

Browser
Name : Mozilla Firefox

Operating System
Name : Windows XP

for (var i = 0; i < 10; i++)
{
$j = _heading4(i).innerHTML;
_alert($j);
_writeFile($j,"foo.txt");
}

For the previous example, the _alert() shows the value I expected (in this case an html anchor tag and end-tag) but what is written to the file "foo.txt" is "_sahi._heading4(0).innerHTML" (0 through 9).

Can anyone help me understand the difference?

Thank you very much,
James

Comments

  • SumitraSumitra Members
    Hi James,

    While working with for loop in Sahi we have to make sure that we "do not use a condition which depends on a page’s DOM". For more Details regarding for loop:

    http://sahi.co.in/w/for-loops

    Use the following script:
    var $headingList = [];
    <browser>
    function getNoofheading(){
        var retVal = [];
        var headings = document.getElementsByTagName("h4");
        for (var i=0; i<headings.length; i++){
            retVal[i] = headings[i].innerHTML;
            
        }
        return retVal;
    }
    </browser>
    _set($headingList, _call(getNoofheading()));
    
    for (var $i = 0; $i <$headingList.length; $i++)
    {
        var $j = $headingList[$i];    
        _writeFile($j + "\r\n","foo.txt");
    }
    


    Regards
    Sumitra
  • Thank you Sumitra. I reread the for-loops page which explained the process. I appreciate your reply.
This discussion has been closed.