Form Filling


SUBMITTED BY: rilp44

DATE: Dec. 5, 2015, 1:51 a.m.

FORMAT: Text only

SIZE: 14.2 kB

HITS: 2004

  1. ''"At the Office of Enrollment Services at Indiana University Bloomington we have been using iMacros to automate data entry tasks into PeopleSoft... and have saved hundreds of hours of data entry time thus far."''
  2. Anne Palmer, Indiana University, iMacros Enterprise Edition
  3. __TOC__
  4. ===Introduction===
  5. Are you tired of filling out the same form over and over again? Then let iMacros help you. Simply put all data to be input into a very straightforward and easily understandable text file and iMacros can read the data from there and submit it to the web site - completely automatic, without your interaction!
  6. The data source can be in either of two different formats: a text file with a list of variables and their values of the form key=value or as a comma separated text file (CSV format). A text file in CSV format can be generated and edited by Microsoft Excel and many other applications.
  7. As a rule of thumb the "list of variables" format is recommend if you have many different variables but only one or a few value(s) for each variable (for example, your detailed address data that you use to fill out online forms). The CSV format is most appropriate for use with a few variables with many different values (for example, a long list of CD's that you want to submit to an auction web site).
  8. More advance users might connect directly to databases to retrieve the data.
  9. (Related example macros: Demo-Datasource, Demo-Loop-CSV-2Web)
  10. (Related example script: Datasource-2-web.vbs, File-2-web.vbs, File-2-web-Method2.vbs, Database-2-web.vbs)
  11. ==Variables [[Image:IMacros-icon.png|iMacros Browser]] [[Image:Ie-icon.png|IE Plug-in]] [[Image:Ff-icon.png|Firefox]] [[Image:Cr-icon.png|Chrome]]==
  12. (Related example macros: Demo-Datasource, Demo-Slideshow )
  13. Variables are, as the name suggests, constructs that allow you to dynamically, usually during runtime, hold different values. This is very helpful when you are trying to follow links that contain changing words or when you want to use the same macro for entering different values into a search engine.
  14. The values (content) of all variables in iMacros are accessed by putting two curly brackets around the variable name. The values of !VAR1 is thus accessed by <nowiki>{{!VAR1}}</nowiki>.
  15. Variables can be part of anything inside the macro (except the commands themselves). For example, you can add them as part of the ATTR string in a TAG or EXTRACT command or as part of the URL statement:
  16. <nowiki>URL GOTO=https://www.onlinestore.com/?shoppingcart={{!VAR1}}&item={{!VAR2}}</nowiki>
  17. You can assign almost any value to a variable. However, when assigning a value to a variable with [[SET]] certain characters need to be escaped or substituted because they imply a certain behaviour to iMacros. When assigning values to variables all whitespaces in the value part must be substituted by <SP> and all newlines must be substituted by <nowiki><BR></nowiki>; double curly brackets must be escaped with #NOVAR# ie. #NOVAR#{{. Note this this only applies ''inside a macro'', e. g with the [[TAG]], [[SET]] or [[ADD]] commands. If you use the [[iimSet]] command of the Scripting Interface, it replaces " " with <SP> and newline with <nowiki><BR></nowiki> automatically.
  18. There are two kinds of variables in iMacros:
  19. ===Built-in variables [[Image:IMacros-icon.png|iMacros Browser]] [[Image:Ie-icon.png|IE Plug-in]] [[Image:Ff-icon.png|Firefox]] [[Image:Cr-icon.png|Chrome]]===
  20. These variables are used to define certain properties of the macro's behavior, for example the macro timeout value:
  21. SET !TIMEOUT_MACRO 300
  22. There are three special built-in variables, !VAR1, !VAR2 and !VAR3 (in the iMacros BRowser and iMacros for Internet Explorer, you can have up to !VAR9 and !VAR0). These variable can be set to anything you like. They are also defined with the SET command
  23. SET !VAR1 hello<SP>world
  24. Alternatively, you can prompt the user to input a value:
  25. PROMPT "Please enter text" !VAR1
  26. ===User-defined Variables ===
  27. These variables are created during runtime ("on the fly"). There are 3 different ways of creating variables:
  28. 1. You may use the command line switch -var_MYVAR like in
  29. imacros.exe -macro myMacro -var_ITEM 15
  30. which creates the variable ITEM during replay of the macro myMacro and gives it the value 15.
  31. 2. The second options is to use the iimSet function of the Scripting Interface. In a Visual Basic Script example this would look like:
  32. iret = imacros.iimSet("ITEM", "15")
  33. 3. Or you may simply use the [[SET]] command as in
  34. SET ITEM 15
  35. Note that the user-defined variables '''should not have a prefixed "!"'''. Only the built-in ones do, like e.g. [[!LOOP]].
  36. == Data Input ==
  37. ===Input from Comma Separated Data (CSV) File ===
  38. <small>[http://wiki.imacros.net/CSV_input Short URL to this section]</small>
  39. Related examples: [[Demo-Loop-Csv-2-Web]], [[File-2-Web.vbs]]
  40. iMacros allows you to specify a text file with comma separated values ([[csv|CSV]]) to be used as input. Imagine, for example, that you want to submit a list of CD's to an online auction. Here is the list of the CD's in the comma separated format:
  41. "ARTIST" , "ALBUM TITLE" , "PRICE"
  42. "Beatles", "Abbey Road", "13.49"
  43. "Beatles", "The Beatles 1,2,3" , "25.49"
  44. "Mozart" , "Symphonies No.40 & 41", "9.98"
  45. "Mozart", "Requiem", "7.50"
  46. Note: Quotation marks are optional in most cases. They are only required if the value itself contains a comma, or a new line.
  47. 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
  48. SET !DATASOURCE OnlineAuction.csv
  49. 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\).
  50. <!--iMacros for Firefox and iMacros for Chrome need to know the number of columns in the CSV file, to read it properly. Set it using
  51. SET !DATASOURCE_COLUMNS 8
  52. for instance. In the iMacros Browser and iMacros for Internet Explorer this command has no effect.
  53. -->
  54. Since we want to insert all datasets into the form we need to loop over the macro, each time inserting the next CD. Therefore, we need to tell iMacros in which line of the datasource we currently are. We do this using the built-in variable !DATASOURCE_LINE. By cunningly using the built-in variable !LOOP we let iMacros take care of the counting. And since the first line is just the header, we would like to skip it and start counting from 2:
  55. <nowiki> SET !LOOP 2</nowiki>
  56. <nowiki> SET !DATASOURCE_LINE {{!LOOP}}</nowiki>
  57. Now we can have the macro fill out the online form with the values from the current CD dataset. We use the built-in variables !COLn, where n represents the number of the columns to put into the form element.
  58. <nowiki> TAG TYPE=INPUT:TEXT FORM=Listing ATTR=NAME:Name CONTENT={{!COL1}} </nowiki>
  59. <nowiki> TAG TYPE=INPUT:TEXT FORM=Listing ATTR=NAME:Album CONTENT={{!COL2}} </nowiki>
  60. <nowiki> TAG TYPE=INPUT:TEXT FORM=Listing ATTR=NAME:Price CONTENT={{!COL3}}</nowiki>
  61. During the execution of the macro the constants in parentheses <nowiki>{{..}}</nowiki> are replaced by the value specified in the data sources.
  62. Please note that you need to use the '''"Play (Loop)"''' button instead of the regular "Play" button if you want to loop through a CSV file. Also don't forget to set the "Max" text box value to the number of the last line you want to reach in your CSV file.
  63. ===Input from Database ===
  64. (Related example macros: Wsh-Submit-2-Web)
  65. (Related example script: File-2-web-Method2.vbs, Database-2-web.vbs)
  66. This example only works with the Enterprise Edition.
  67. iMacros can read data directly from any Windows database using the Scripting Interface and a few lines of code.
  68. This example code in Visual Basic Script connects to a Microsoft Access database:
  69. ' open database
  70. set rs = CreateObject("ADODB.Connection")
  71. rs.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" _
  72. & mypath & "IIM-TEST-SUBMIT.MDB")
  73. ' use SQL to select information
  74. sql = "select * from table1"
  75. set rs = rs.Execute(sql)
  76. ' start iMacros
  77. set iim1= CreateObject ("iMacros")
  78. iret = iim1.iimInit
  79. iret = iim1.iimDisplay("Submitting Data from MS ACCESS")
  80. ' loop through result dataset
  81. do until rs.eof
  82. 'Set the variable
  83. iret = iim1.iimSet("FNAME", rs.fields(0))
  84. iret = iim1.iimSet("LNAME", rs.fields(1))
  85. iret = iim1.iimSet("ADDRESS", rs.fields(2))
  86. iret = iim1.iimSet("CITY", rs.fields(3))
  87. iret = iim1.iimSet("ZIP", rs.fields(4))
  88. iret = iim1.iimSet("STATE-ID", rs.fields(5))
  89. iret = iim1.iimSet("COUNTRY-ID", rs.fields(6))
  90. iret = iim1.iimSet("EMAIL", rs.fields(7))
  91. 'Run the macro
  92. 'Note: This is the SAME macro, as in the FILE-2-WEB-METHOD2.VBS example script!!!
  93. iret = iim1.iimPlay("wsh-submit-2-web")
  94. If iret < 0 Then
  95. MsgBox iim1.iimGetLastError()
  96. End If
  97. rs.movenext
  98. loop
  99. iret = iim1.iimDisplay("Done!")
  100. iret = iim1.iimExit
  101. WScript.Quit(0)
  102. ==Tabbed Browser [[Image:IMacros-icon.png|iMacros Browser]] [[Image:Ie-icon.png|IE Plug-in]] [[Image:Ff-icon.png|Firefox]] [[Image:Cr-icon.png|Chrome]]==
  103. [[Image:Tabbed_Browser.png|500px|thumb|Using Tabs]]
  104. (Related example macros: Demo-Tab )
  105. The iMacros Browser [Standard and Enterprise Edition only] includes a tabbed browsing interface that makes managing web sites with multiple open pages a snap. When a web page opens a new window iMacros automatically opens it in a new tab in the background. If the user changes to another tab a TAB command is automatically added during recording.
  106. You can close tabs while browsing by right-clicking on the tabs (not the browser window itself!). This will open up a context menu with the options to close the tabs. The following example shows the basic actions you can do with the TAB command
  107. ' open a webpage in the first tab
  108. URL GOTO=http://www.imacros.net
  109. ' open a new tab
  110. TAB OPEN
  111. ' get new tab to foreground
  112. TAB T=2
  113. ' load another page
  114. URL GOTO=http://www.google.com
  115. ' close the second tab
  116. TAB CLOSE
  117. TAB T=1
  118. iMacros for Internet Explorer supports tabs in IE 8 and IE 9 (not in Windows XP, though!) Do not forget to enable IE to open popups in tabs (Internet Options in IE Tools menu) if you want to use this feature.
  119. ==Frames [[Image:IMacros-icon.png|iMacros Browser]] [[Image:Ie-icon.png|IE Plug-in]] [[Image:Ff-icon.png|Firefox]] [[Image:Cr-icon.png|Chrome]]==
  120. [[Image:Frame-dom-inspector-f6.png|150px|thumb|Frame in Object Tree]]
  121. iMacros handles pages with frames automatically. It inserts FRAME statements that indicate to which frame the following TAG or similar command refers. Please note that TAG will fail if it is not directed to the correct frame.
  122. If the frame has a name, iMacros will use it in the FRAME statement, otherwise its index (the position of the frame in the page's object tree) is used.
  123. ;Hint
  124. :When recording in the iMacros Browser or Internet Explorer, use Click Mode = Expert to get the frame number as a comment in the recorded macro. Later you can edit your macro and decide which suits better your needs. Some websites use random names but fixed indexes, in this case it is better to refer to the frame number instead of the default frame name.
  125. ==Fine Tune TAG Commands [[Image:IMacros-icon.png|iMacros Browser]] [[Image:Ie-icon.png|IE Plug-in]] [[Image:Ff-icon.png|Firefox]] [[Image:Cr-icon.png|Chrome]]==
  126. Normally the TAG commands work the way they are recorded by iMacros, but sometimes you need to manually fine tune them. If an error occurs during replaying a TAG command it might be due to one of the following problems.
  127. ===Wildcards ===
  128. Some web sites are created dynamically from databases and the links contain unique numbers - the so-called session ID - each time you visit a page. While this technique helps the web site owner it poses a problem to iMacros. This is because during recording the session ID, which is often part of links, was written into the macro as part of the TAG command. During replay the session ID is different, thus iMacros does not find the exact link and produces an error. The solution is to replace the changing part of a link (or extraction) with the * symbol, which is read by iMacros as a wildcard. The wildcard causes iMacros to accept any character where the * is placed.
  129. ====Example====
  130. Tag line as recorded by iMacros:
  131. TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:/kb/ki.dll/ke.kb.gz?kbb;532452&&2&&&&&nc ATTR=NAME:zipcode CONTENT=85250
  132. If you record the same macro a second time you will see that we get the same TAG line except one number - this is the session ID the website is using.
  133. TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:/kb/ki.dll/ke.kb.gz?kbb;532244&&2&&&&&nc ATTR=NAME:zipcode CONTENT=85250
  134. Replace the session ID with *:
  135. TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:/kb/ki.dll/ke.kb.gz?kbb;*&&2&&&&&nc ATTR=NAME:zipcode CONTENT=85250
  136. Actually, you could also remove most or all of the static parts of the FORM information as well. Exactly how much you can remove depends on the website. You still need enough information for iMacros to uniquely identify the page element. In our example, the result looks like:
  137. TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:/kb/* ATTR=NAME:zipcode CONTENT=85250
  138. or even
  139. TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:* ATTR=NAME:zipcode CONTENT=85250
  140. '''Note:''' ''TXT:* is not the same as TXT: (without *).'' If only TXT: is used, this means you are looking for an element where the text attribute is "", if you are using TXT:* this means that the text attribute can have any value (= same as omitting the text attribute altogether). This applies to any attribute, not just TXT.
  141. =====Related forum posts:=====
  142. * [http://forum.imacros.net/viewtopic.php?t=11663 Click every button on a webpage using wildcards.]

comments powered by Disqus