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.
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}
See also: this post that describes a scenario where using a normal TAG command to upload the file may work by adding the CONTENT parameter to the command that clicks the Browse (or similarly named) button on the page for selecting the file.