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.

_navigateTo - variable

alamoonalamoon Members
edited November -1 in Sahi - Open Source
hi,
how to use : _navigateTo with a variable like this:

_navigateTo($linkArray[0]); or _navigateTo($link)
or
_call(window.open($linkArray[0], "MyWindowName"));
or
browser.navigateTo($linkArray[0]);


it doesnt work :-(

Comments

  • I just tried this,

    var $ar = "http://www.sahi.co.in/demo", "[url]http://www.sahi.co.in/forums[/url]";
    _navigateTo($ar[0][0]);
    _navigateTo($ar[0][1]);

    its working fine. Can you tell me what error you are getting in the logs?
  • it's working fine but $ar has a terminal value, in my code $ar is a variable:

    var j = 24 ;
    for(var i = 0; i < 20; i++){
    $linkArray = top.document.links[j];
    j++; j++;
    }

    // browse the saved links

    _navigateTo($url);



    //
  • sorry here the right code:
    var j = 24 ;
    for(var i = 0; i < 20; i++){
    $linkArray = top.document.links[j];
    j++; j++;
    }

    // browse the saved links
    $url = $linkArray[0];
    _navigateTo($url);
    //
  • if you declare as,
    var $linkArray = top.document.links[j];
    then $linkArray will be considered as a string and not as an array. so $linkArray[0] returns first character of the string.

    Try using it as
    var $linkArray = new Array();
    var j = 24 ;    
    for(var i = 0; i < 20; i++){ 
       $linkArray[i] = top.document.links[j]; 
       j++; j++;
    }
                   
    // browse the saved links
    $url =  $linkArray[0];
    _navigateTo($url);
    

    and make sure that url in $linkArray[0] is formatted correctly by alerting it.
  • i tried it but :-((

    by alert the url from $linkArray[0] is formatted correctly.
  • can you paste the url here which is not working?
  • narayannarayan Administrators
    Hi alamoon,

    To fetch values from the browser, you need to use _set.
    A simple sample script is here:
    var $linkArray = new Array();
    for(var $i = 0; $i < 5; $i++){
        _set($href, top.document.links[$i].href);
        $linkArray[$i] = $href;
    
            // There is a bug in Sahi which is preventing the assignment of value to an array variable like this:
            // _set($linkArray[$i], top.document.links[$i].href);
            // The next release should have this fixed.
    }
                   
    // browse the saved links
    var $url =  $linkArray[0];
    _navigateTo($url);
    
  • i tried it, but nothing :-((

    the system seems not accept :
    _set($href, top.document.links[$i].href);
  • the isn't to fetch the values from a browser but just to navigate to a variableurl.
  • i get it :-)))))))))))))

    var $linkArray = new Array();

    // copy the links
    var j = 24 ;
    for(var i = 0; i < 20; i++){
    $linkArray = top.document.links[j];
    j++; j++;
    var $url = $linkArray[0];
    _call(window.open($url, $url ));
    _wait(6000);

    }
    //

    it works now, thank you for support.
Sign In or Register to comment.