Sample Code

From iMacros
Jump to: navigation, search

Examples for using iMacros efficiently.

All macros and scripts listed here are included in the default installation of iMacros (unless otherwise noted). The example batch files and scripts in iMacros 8 can be found at "C:\Documents and Settings\<user name>\Documents\iMacros\Examples" if you selected the default installation directory during installation.
Location of the iMacros example projects after a default iMacros 8 installation (in the User's Documents folder).

No vendor specific scripting language. iMacros does not use an awkward, proprietary vendor specific scripting language. The iMacros Browser, Internet Explorer (with iMacros Add-on), Google Chrome (with iMacros Add-on) and Firefox (with iMacros Add-On) can be controlled with any Windows programming or scripting language. We have included samples for the most popular languages on this page and in the iMacros download. The basic usage is the same in every language.


Internet Macros are used to describe the page specific interaction. The syntax is based on HTML.

  1. Demo-AJAX-Tree Move element of an AJAX tree view by drag & drop. No fixed coordinates required.
  2. Demo-ArchivePage Save the current page with custom file name
  3. Demo-Datasource Enter data from textfile (CSV) into web form
  4. Demo-DirectScreen Automate Java Calculator Applet
  5. Demo-Download Automate file downloads
  6. Demo-Draw Record mouse movements for e.g. java applets
  7. Demo-Extract Extract text, HTML code, links, tables
  8. Demo-ExtractAndFill Extract data and directly fill it into another web site
  9. Demo-ExtractRelative Use relative positioning for more easy extraction
  10. Demo-Extract-Table Extract complete table with one command and save data to text file
  11. Demo-Eval Test for value and time ranges in your macro and anything else that can be done with Javascript
  12. Demo-FillForm Fill forms automating input boxes, drop down selections, checkboxes, radiobuttons, etc.
  13. Demo-FillForm_XPath Use XPath to navigate through elements and attributes in an XML document
  14. Demo-Filter Filter pictures for faster page loading
  15. Demo-Flash Automate flash applets
  16. Demo-Frames Automate sites using HTML frames
  17. Demo-ImageDownload Download picture to local disc, take screenshots
  18. Demo-ImageRecognition Automate e.g. a flash plugin by its graphical elements
  19. Demo-JavascriptDialog Handle pop-up dialogs
  20. Demo-Keyword-Assert Asserts that a specific keyword appears on a web page
  21. Demo-Loop-Csv-2-Web Fill textfile (CSV) data to web form
  22. Demo-OfflineDialogs Automates pop-up dialogs (macro runs on local HTML code)
  23. Demo-OfflineExtract Extract data from web sites (macro runs on local HTML code)
  24. Demo-Print Print websites and PDF documents
  25. Demo-SaveAs Save Website in various formats
  26. Demo-SavePDF Download PDF files
  27. Demo-SaveTargetAs Download and save files using custom paths and file names
  28. Demo-Slideshow Loop through thumbnails
  29. Demo-Stopwatch Measure detailed website response times
  30. Demo-Tabs Make use of tabs
  31. Demo-Tagposition The relevance of the POS value in TAG commands
  32. Demo-TakeScreenshots Take screenshot of full page (not just the part visible in the browser)
  33. Demo-Upload Fill in file upload fields
  34. Demo-WebPageDialog iMacros handles web page dialogs
  35. Demo-Web-Test Use macro for web testing
  36. Parse Twitter Tweets Extract information from tweets

Batch Files

The iMacros Browser includes a command line interface, so it can be controlled via batch files.

  1. Example-Batchfile.bat
  2. Example-ErrorLevel
  3. Tray-Example-Batchfile.bat

Task Scheduler

To schedule a certain macro to run at a certain hour, please use the Windows task scheduler and the iMacros command line interface (same commands as used in Batch Files.)

You can also call VBS scripts from the command line.

Related chapter: How to run iMacros unattended

Related FAQ: How can I set up a 24 hours a day, 7 days a week (non-stop) operation with iMacros?


An ASP sample project is included in the iMacros download. It uses the iimRunner feature.


An ASP.NET sample project is included in the iMacros download. It uses the iimRunner feature.

iMacros ships with a 32-bit and 64-bit version of the Scripting Interface. This allows you to run iMacros directly from any 64-application on Windows x64 systems. For example, you can use it with ASP.NET (IIS) in 64-bit mode. The use of the 64-bit version requires no code changes.

Case Study: A well-known site that runs iMacros via ASP.NET is AlertFox Website Monitoring.


C# sample projects are included in the iMacros download. The samples especially show the threading features of iMacros. You can run and control many browsers simultaneously. If you develop 64-bit applications, a 64-bit version the 64-bit iMacros Scripting Interface is automatically used.


C++ sample projects are available here.

And here is a step-by-step tutorial for a "Hello iMacros World".

Database Access

iMacros can connect to any database or backend system via its API. The VBS examples below use the ACCESS database, but you can use them with SQL Server, Oracle and any other database by only changing the connection string in the script.

  1. database-2-web.vbs Submit database information to a website. Shows how to query any database.
  2. extract-2-database.vbs Web scrape data into a database.


A step-by-step tutorial can be found here: Delphi


The iMacros Browser, IE and Firefox can be integrated with all Microsoft Office products (e. g. Excel, Access). Please see the VBA section for example projects.


Please see the FoxPro tutorial.


Please see the user forum for an Eclipse tutorial and a NetBeans tutorial.


The regular Windows Scripting Interface can be used from within JavaScript and JScript.

In addition, iMacros for Firefox has a built-in Javascript Scripting Interface. Its syntax is a sub-set of the regular Web Scripting interface.


Please see the Perl tutorial.


A PHP sample project is included in the iMacros download. It uses the iimRunner feature.


Please see the Python tutorial.


Please see the PowerShell tutorial.


Please see the Ruby tutorial.


Please see the TCL page.

VBS (Visual Basic Scripting)

The following examples are based on the Windows Scripting Host (WSH, VBScript) that is part of Windows.

  1. combine-macros.vbs Shows how to create a custom error report log file
  2. connect-to-ie.vbs Remote control Internet Explorer
  3. connect-to-fx.vbs Remote control Mozilla FireFox
  4. connect-to-cr.vbs Remote control Google Chrome
  5. connect-to-iimrunner.vbs Shows how to work with iimRunner.exe
  6. database-2-web.vbs Submit database information to a website. Shows how to query any database.
  7. extract-2-file.vbs Web scrape data into a plain text file.
  8. extract-2-database.vbs Web scrape data into a database.
  9. extract-and-fill.vbs Web scrape data from one website and submit it to a second website.
  10. file-2-web.vbs Submit information from a text file to a website (Method 1)
  11. file-2-web-method2.vbs Submit information from a text file to a website (Method 2)
  12. get-exchange-rate.vbs Extract exchange rate from a website. Runs in tray.
  13. get-response-times.vbs Measure response times and use them in script.
  14. iimRunner_ASP.vbs Connect to iMacros via iimRunner, like when using ASP or ASP.NET
  15. random-numbers.vbs Fill an online form with random numbers.
  16. send-macro-code.vbs Directly send macro code to iMacros instance instead of calling locally stored macros.
  17. self-test.vbs Run all iMacros demo macros and create a test report.
  18. stresstest.vbs Run several iMacros instances in parallel.
  19. Create loops with VBS Tutorial with screenshots
  20. Loop only parts of a macro Tutorial with screenshots

Important: iMacros can be controlled with same syntax shown here in any Windows programming and scripting language. Please see also the Tutorials page.

How to execute

In order to execute scripts copied from this site or some other source, do the following:

  • open a new file (e.g. in notepad)
  • copy the VBS code to it
  • save it as *.vbs
  • run the script by double clicking the vbs file)


VB.NET sample projects for Visual Studio 2003 and 2005 are included in the iMacros download.. The samples especially show the threading features of iMacros. You can run and control many browsers simultaneously.


A complete VB6 projects is included in the iMacros download. In addition, all VBS and VBA samples work with VB6 with no or almost no modifications.


The iMacros Browser, IE and Firefox can be integrated with all Microsoft Office products (e. g. Excel, Access):

  1. Excel-VBA-Submit-and-Extract (with screenshots)
  2. Excel-VBA-StockSearch

Recent Project Samples

Click here for some recent project samples

Error Handling

iMacros includes detailed error handling. Even a web browser crash or freeze does not stop the Scripting Interface. Instead, it will simply return an error code and you can start a new instance. Please see the list of general iMacros Error-Codes and Scripting Interface Return Codes.

For more information, please see the Tutorials chapter.