cancel
Showing results for 
Search instead for 
Did you mean: 

Script to download a file from the web

Highlighted
New Contributor

Script to download a file from the web

Hi there,
 



I am new to TestComplete and can't find any info on how to write a script to
download a file from the internet.

I tried the following :

 


 

but that does not do anything.

Anyone knows how to do this ?




Thanks

Philippe


1 REPLY 1
Highlighted

RE: Script to download a file from the web

Hi Philippe,




This method can be used with files which reside on a local or a network drive. It cannot download files from the Internet.




You can download a file by using the script below. It sends an HTTP request by using the XMLHTTP ActiveX object (it's also possible to use the WinHttpRequest ActiveX object instead).




[JScript, C#Script, C++Script]




    // Specify the source and destination file names


    var strHDLocation = "c:\\temp\\filename";




    // Download the file

    var objHTTP = new ActiveXObject("MSXML2.XMLHTTP");

    //or

    //var objHTTP = new ActiveXObject("WinHttp.WinHttpRequest.5.1");

    objHTTP.open("GET", strFileURL, false);

    objHTTP.send();




    if (objHTTP.Status == 200)

    {

      var objADOStream = new ActiveXObject("ADODB.Stream");

      objADOStream.Open();

      objADOStream.Type = 1; //adTypeBinary




      objADOStream.Write(objHTTP.ResponseBody);

      objADOStream.Position = 0;    //Set the stream position to the start




      var objFSO = new ActiveXObject("Scripting.FileSystemObject");

      if (objFSO.FileExists(strHDLocation)) objFSO.DeleteFile(strHDLocation)

      objADOStream.SaveToFile(strHDLocation);

      objADOStream.Close();

    }

-----

Alexander
Customer Care Manager
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!
Top Kudoed Authors