Automating a tricky file upload dialog

Information related to the use of iMacros for form filling and data upload.

Moderator: iMacros Moderators

Automating a tricky file upload dialog

by Tom, Tech Support on Wed Apr 06, 2011 1:32 am

There are many cases where a web page presents a file input field for entering/selecting a file to upload. In these cases, it is very easy to use a simple TAG command for the input field and specify the appropriate file in the CONTENT parameter, as shown in the Upload.iim demo macro that ships with iMacros.

However, there are also cases where an input field is not provided on the web form (or it is not directly editable), and you can only choose the file by using a file upload dialog, which is usually presented after clicking a button or link. There are even cases where automatic click-mode does not work for recording the click on the upload button, and you must use DirectScreen or IMAGECLICK to click the button, as in the following example.

Tricky File Upload Dialog.png

The problem is, once you are presented with the file upload dialog, how do you automate it to specify the file you want to upload?

The answer is: use the DS CMD=KEY command after the dialog appears to send the path/name of the file and press Enter.

The following macro demonstrates just how to do this for the example page shown above:

Code: Select all
VERSION BUILD=7221254
TAB T=1
TAB CLOSEALLOTHERS
SIZE X=800 Y=867
URL GOTO=http://kleinanzeigen.ebay.de/anzeigen/p-anzeige-aufgeben.html
TAG POS=1 TYPE=A FORM=ID:pstctgry-frm ATTR=ID:cat_195
TAG POS=1 TYPE=A FORM=ID:pstctgry-frm ATTR=ID:cat_275
TAG POS=1 TYPE=BUTTON:SUBMIT FORM=ID:pstctgry-frm ATTR=TXT:Weiter
TAG POS=1 TYPE=INPUT:RADIO FORM=ID:adForm ATTR=ID:adType1&&VALUE:OFFER CONTENT=YES
TAG POS=1 TYPE=INPUT:RADIO FORM=ID:adForm ATTR=ID:posterType1&&VALUE:PRIVATE CONTENT=YES
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:adForm ATTR=ID:postad-title CONTENT=Italien<SP>-<SP>Ferienwohnung<SP>mit<SP>Garten<SP>-<SP>4<SP>Personen<SP>max.
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:adForm ATTR=ID:pstad-price CONTENT=290
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:adForm ATTR=ID:pstad-zip CONTENT=80331
TAG POS=1 TYPE=TEXTAREA FORM=ID:adFormBottom ATTR=ID:pstad-descrptn CONTENT=blah<SP>blah<SP>blah

' Click the file upload button
DS CMD=CLICK X=320 Y=517

' Wait a second to give the dialog a chance to pop up
WAIT SECONDS=1

' Send the path/name of the file and Enter to the dialog
DS CMD=KEY CONTENT=C:\Temp\Current.png{ENTER}
Regards,

Tom, iMacros Support
Tom, Tech Support
 
Posts: 3297
Joined: Mon May 31, 2010 9:59 am

Return to How-To's and Examples for Form Filling

Who is online

Users browsing this forum: No registered users and 1 guest

Website Monitoring