Related example macros: Demo-Datasource
Related example script: Datasource-2-web.vbs
You can also use data from a list of variable input file. The information in this format is saved in the form of key-value pairs, like
key1=value1
key2=value2
To use input in that format, create a plain text file that contains the information you want to submit. The first line in this input file must be
[iOpus]
In this example we create a file that contains the information on ordering "lunch". lunch.txt could look like this:
[iOpus]
name=Mr.<SP>Tester
main=2
drink=2
smallsizedrink=NO
myremarks=Deliver<SP>to<SP>home<SP>address:<BR>1629<SP>4th<SP>Avenue<BR>Thanks!<BR>Tom
We now need to tell the iMacros macro where the data input file can be found. For that, we use the built-in variable !DATASOURCE
SET !DATASOURCE lunch.txt
If you do not use any path information (like C:\myPath\) in the !DATASOURCE value, the file is assumed to lie in the standard datasources directory, which can be specified in the Paths tab of the Options dialog. The default directory is in the datasources\ directory of your iMacros installation (e.g. C:\Program Files\iMacros\datasources\).
After we have specified the location of the input data, it is already ready to use! iMacros creates variables called after the key part of the key-value pairs. The value of this variable is the value of the key-value pair. You can now use these variable to fill the form:
TAG TYPE=INPUT:TEXT FORM=NAME:TestForm2 ATTR=NAME:Name CONTENT={{name}}
TAG TYPE=SELECT FORM=NAME:TestForm2 ATTR=NAME:main CONTENT={{main}}
TAG TYPE=SELECT FORM=NAME:TestForm2 ATTR=NAME:drink CONTENT={{drink}}
TAG TYPE=INPUT:CHECKBOX FORM=NAME:TestForm2 ATTR=NAME:C8&&VALUE:ON CONTENT={{smallsizedrink}}
TAG TYPE=TEXTAREA FORM=NAME:TestForm2 ATTR=NAME:Remarks CONTENT={{myremarks}}
During the execution of the macro, the constants in parentheses {{..}} are replaced by the value specified in the data sources.
Multiple Sets of Key-Value Pairs
If you want iMacros to read different sets of key-value pairs for each loop, add a number at the end of the key and add !LOOP to the end of the name inside the macro. The datasource input.txt could then look like this:
[iOpus]
name1=Tom<SP>Tester
name2=Ann<SP>Smith
name3=Nicole<SP>Frank
main1=2
main2=1
main3=3
The complete macro would then look like this:
SET !DATASOURCE input.txt
TAG TYPE=INPUT:TEXT FORM=NAME:TestForm2 ATTR=NAME:Name CONTENT={{name!LOOP}}
TAG TYPE=SELECT FORM=NAME:TestForm2 ATTR=NAME:main CONTENT={{main!LOOP}}