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.

Can't use getElementsByTagName.length value as loop parameter

I have following code in sahi script:

var $inputLength = document.getElementsByTagName("button").length;

_alert($inputLength);


for(var $i=0; $i<$inputLength; $i++)
{
_alert("test");

}

Result is:

_alert($inputLength); -> gives me 21 in popup

but

for loop doesn't start code inside brackets. I don't know why "$inputLength" value isn't assigned as 21 number ? Is "21" a string ?

Answers

  • I see that _alert(typeof $inputLength); gives a number, so whyd loop can't be started?
  • as far as i know, there is a bug in the Javascript engine so you can't use

    if ()
    {
    }

    you have to write it as

    if () {
    }

    if this does not fix it, try to use

    var $inputLength = 0
    _set(inputLength ,document.getElementsByTagName("button").length);
    for(var $i=0; $i<$inputLength; $i++) {
    _alert("test");
    }
Sign In or Register to comment.