SaveTargetAs
Web function.
The SaveTargetAs function simulates a right click on an HTML element and selection of Save Target as option in the context menu.
Usage
The function right clicks on an HTML element and selects in the context menu the Save Target As option.
Syntax
ret=SaveTargetAs(<html_descriptor>, <path>,<extension>)
Parameters
<html_descriptor>, identifier for the HTML element to save. See HTML descriptor for each HTML objects identification. Use Recording mode for generating automatically the descriptor (just record a right click on the link).
<path>, string, directory where to save the file.
<extension>, string, extension for the saved file ("htm", "php" for examples). It must be the correct extension as the one specified when you do the Save Target As manually.
Return value
Ret, numeric return code. The function returns 0 if successfull. If the file cannot be created (or overwritten), the function returns 26. If an Internet error occurs, a negative error code is returned. The dialog boxes opened by the function (Save as dialog box, File Download dialog box) are automatically closed if an error occurs.
List of negative error codes
-1
No browser in use (no previous UsePage or StartBrowser)
-3
Bad descriptor, invalid syntax
-4
The browser has been lost (for instance because of a Closewindow)
-5
Page not found
-8
Specified element not found
-12
Download timeout (the file could not be saved within the #ActionTimeout time)
-11
Any other error
-404,405
Usual http error codes (requires IE 6 or above)
The return code can be used for Error Handling.
Remarks
Only the path and the extension are specified, the file is saved using the name provided by the web page. If the specified directory does not exist, it is created. If the file already exists, it is automatically replaced. If for any reason, the existing file cannot be deleted before saving the new file with the same name, an error is reported.
At replay, the function waits for the HTML element to be displayed before saving the target. The timeout is the value of #ActionTimeout (the default is 30 seconds).
Example
On WinTask Web site, we save the target which is under the link WinTask new version:
StartBrowser("IE","www.wintask.com")
UsePage("WinTask - Automation software and Task Scheduler. Macro software with Macro Recorder")
SaveTargetAs("A[INNERTEXT= 'WinTask ']", "c:\test", "htm")
CloseBrowser()
The file is saved under c:\test with the name hottest_new_version.htm which is the original filename of the HTML element.