Forum Discussion

BTscott's avatar
BTscott
Contributor
7 years ago
Solved

Downloading a File via Redirect Link

Greetings,

 

I am trying to construct a test for downloading a file from my employer's site in different browsers (IE, FireFox, Chrome) and I am using the Javascript solution provided here:

 

https://support.smartbear.com/viewarticle/8999/?st=0

 

However, I receive an error when I provide the download URL as the target URL (strFileURL). It may or may not be important to note that the URL I provide to the Javascript function is a redirect URL: https://[site]/common/redirect.cfm?/tcmain/common/filedownload.cfm+Filename=[FileName].xls&Path=//carrier%20rosters/Medical/&AdminPath=true

 

Here is the error I receive when executing the javascript function:

 

JavaScript runtime error.

Error: 0x80072ee6

Error location:
Line: 20 Column: 11.
 
Line 20 (from download file solution js):

// Download the file
objHTTP.open("GET", SrcFileURL, false);

 

Any advice would be greatly appreciated. Thank you.

 

12 Replies

  • This is how my javascript function is set up:

     

    /**
    * Check provided column to see if provided value exists within file.
    * If value exists, return row index in which first match was found.
    * If value is not found for given column, return -1
    * 
    * @param SrcFileURL     the link for downloading file
    * @param DestFilepath   the destination in which to save file
    * @param SearchValue    the value to search for within file
    *
    * @return   TRUE if file exists for destination path (download successful)
    */
    function downloadFile(SrcFileURL, DestFilepath) {
      var objHTTP = new ActiveXObject("MSXML2.XMLHTTP");
      var objFSO  = new ActiveXObject("Scripting.FileSystemObject");
      var retVal;
    
      Log.Message("Downloading file", SrcFileURL, pmNormal);
    
      // Download the file
      objHTTP.open() .open("GET", SrcFileURL, false);
      objHTTP.send();
    
      /* wait for file to finish downloading */
      while((objHTTP.readyState != 4) && (objHTTP.readyState != 'complete')) { 
        Delay(100);
      } /* while: file is still downloading */
    
      if (200 == objHTTP.Status && objFSO.FileExists(DestFilepath)) {
        Log.Message("Finished downloading file", "File downloaded to: " + DestFilepath, pmNormal);
    
        retVal  = true;
      } /* if: download was successful */
      else {
        Log.Error("The " + SrcFileURL + " file was not found." + 
        " The returned status is " + objHTTP.Status);
        retVal  = false;
      } /* else: download failed */
    
      return retVal;
    } /* end function: ownloadFile(SrcFileURL, DestFilepath) */
    • BTscott's avatar
      BTscott
      Contributor

      I updated the following declarations 

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

       

      Now, I get an error on the first declaration stating that ActiveXObject is not defined.

       

      • BTscott's avatar
        BTscott
        Contributor

        I updated the following declarations

        var objHTTP = getActiveXObject("MSXML2.XMLHTTP");
        var objFSO  = getActiveXObject("Scripting.FileSystemObject");

        Now I am back to receiving the '0x80072ee6' error