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.

Open multiple URLs on Single Browser

nagarnagar Members
edited November -1 in Sahi - Open Source
Hi All,

I have a text file, containing multiple URLs. For example:
www.google.com
www.gmail.com
www.yahoo.com

All this URLs are written on a text file. I want to open these URLs on a browser, one by one.
Like, once I set URL www.google.com and press ENTER, once it is loaded completely, I set another URL and press ENTER ... and so....

Is this possible using Sahi? If yes then How?

regards,
nagar

Comments

  • Hi nagar,

    _readFile API is used to read the file and return the content of the file as single string.

    Once you have got the string, you can split it based upon the delimiter newline character(\n).

    I have tried the following script with
    http://sahi.example.com/_s_/dyn/Driver_initialized?browserType=chrome url. It works fine for me.
    Try with the following script,
    var $fileContents = _readFile("path to file");
    var $lines = new Array();
    $lines=$fileContents.replace(/\r/g, '').split("\n");
    for (var $i=0; $i<$lines.length; $i++){
      _setValue(_textbox("_sahi_ignore_url"),$lines[$i]);
      _click(_submit("Go"));
      _wait(5000);
      _navigateTo("http://sahi.example.com/_s_/dyn/Driver_initialized");
    }
    

    and iam able to navigate between various url specified in txt file.

    Hope this might help you.

    Regards,
    Theeran.
  • nagarnagar Members
    edited February 2012
    Hi Theeran,

    Thanks for the response.

    Unfortunately, I am not able to understand your code. These lines are confusing me:
    _setValue(_textbox("_sahi_ignore_url"),$lines[$i]);
    _click(_submit("Go"));
    However, I tried in this way.
    var $output = _readFile("file name");

    var $lines = $output.replace(/\r/g, '').split("\n");

    for(var $i=0; $i< $lines.length; $i++)
    {
    _navigateTo($lines[$i],true);
    _wait(5000);
    }

    Using controller, when I set the URL as http://www.google.com/ and then try to run above code.
    It joins the first URL of the txt file (www.gmail.com) and henceforth, gives error.
    So, after running the code, in the url bar, url becomes, http://www.google.co.in/www.gmail.com

    Kindly help in this issue.
  • Hi nagar,

    Unless a URL starts with http:// or /, it will be treated as a relative URL. This is the correct URL resolution behaviour. You just need to use _navigateTo("http://"+$lines[$i]).

    Try with the following script,
    var $fileContents = _readFile("path to file");
    var $lines = new Array();
    $lines=$fileContents.replace(/\r/g, '').split("\n");
    for (var $i=0; $i<$lines.length; $i++){
      _navigateTo("http://"+$lines[$i]);
      _navigateTo("http://sahi.example.com/_s_/dyn/Driver_initialized");
    }
    

    This might help you.

    Regards,
    Theeran.
  • Hi Theeran,

    Thanks a lot. Now it is working fine.

    But, now I am getting strange error on the log file.
    undefined: Script error. (:)
    No trace available
    websites which take longer time to load (like, yahoo/ndtv), are throwing this kind of error.

    My Text file contains below urls:
    www.cyberoam.com
    www.yahoo.com
    www.google.com
    www.ndtv.com
    www.timesofindia.com
    www.google.com

    Please help in this matter.
Sign In or Register to comment.