Knowledge Base Article

Home Page > Knowledge Base > Rapise

Home Page > Knowledge Base > Rapise > Rapise Web

Article Automating HTML File Upload Boxes with Rapise 2.2+

by Jim R. on Friday, December 19, 2014

Sometimes you have to automate the uploading of files using an HTML file upload control. This articles explains how to record and playback such a script.
For this example, we shall be using the following website:

http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_FILE.html


This contains the following file upload box:



Which is created from the following HTML:

<FORM METHOD=POST ENCTYPE="multipart/form-data" ACTION="../cgi-bin/mycgi.pl"> File to upload: <INPUT TYPE=FILE NAME="upfile"><BR> <INPUT TYPE=SUBMIT VALUE="Submit"> </FORM>

To record this script in Rapise, simply use the LEARN (F2) function to learn the BROWSE button above. You can then write the following code in Rapise to automate the upload:

    //Click the upload 'Browse'
    SeS('upfile').DoLClick(0, 0);
       
    //Send the filename and enter
    Global.DoSendKeys('C:\\temp\\small text file.txt');
    Global.DoSendKeys('{ENTER}');   


The object 'upfile' should be replaced with the object that you learned from your application.

Note: We need to use the DoLClick(0,0) function rather than the normal DoClick() function since we need to simulate a real user's left-click and not trigger the browser event directly as otherwise the browser security will prevent the enter of the filename.


Attached to this sample is a copy of a complete working sample.

Attachments
Article Info
Last Updated: 12/19/2014
Article ID: KB101
# Views: 1371
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.