The renewal maintenance has officially ended for Progress iMacros effective November 30, 2023.
This Wiki site will also no longer be moderated from the Progress side.
Thank you again for your business and support.
Sincerely, The Progress Team
Difference between revisions of "Sample Code"
(123 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
− | '''Examples for using iMacros efficiently.''' | + | '''Examples for using iMacros efficiently.''' |
− | ''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) 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 | + | All macros and scripts listed here are '''included in the default installation of iMacros Samples''' (unless otherwise noted). |
+ | |||
+ | ''No vendor specific scripting language.'' iMacros does '''not''' use an awkward, proprietary vendor specific scripting language. The iMacros Browser, Internet Explorer (with iMacros for IE), 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. The basic usage is the same in every language. | ||
== Macros == | == Macros == | ||
− | + | iMacros macros are used to describe the page specific interaction. | |
− | #[[Demo-AJAX-Drag-Drop]] Automate drag & drop in AJAX. ''No'' fixed coordinates required. | + | <!--#[[Demo-AJAX-Drag-Drop]] Automate drag & drop in AJAX. ''No'' fixed coordinates required.--> |
− | #[[Demo-AJAX-Tree]] Move element of an AJAX tree view by drag & drop | + | #[[Demo-AJAX-Tree]] Move element of an AJAX tree view by drag & drop. ''No'' fixed coordinates required. |
#[[Demo-ArchivePage]] Save the current page with custom file name | #[[Demo-ArchivePage]] Save the current page with custom file name | ||
#[[Demo-Datasource]] Enter data from textfile (CSV) into web form | #[[Demo-Datasource]] Enter data from textfile (CSV) into web form | ||
+ | #[[Demo-DirectScreen]] Automate Java Calculator Applet | ||
#[[Demo-Download]] Automate file downloads | #[[Demo-Download]] Automate file downloads | ||
#[[Demo-Draw]] Record mouse movements for e.g. java applets | #[[Demo-Draw]] Record mouse movements for e.g. java applets | ||
Line 15: | Line 18: | ||
#[[Demo-ExtractRelative]] Use relative positioning for more easy extraction | #[[Demo-ExtractRelative]] Use relative positioning for more easy extraction | ||
#[[Demo-Extract-Table]] Extract complete table with one command and save data to text file | #[[Demo-Extract-Table]] Extract complete table with one command and save data to text file | ||
+ | #[[Demo-Eval]] Test for value and time ranges in your macro and anything else that can be done with Javascript | ||
#[[Demo-FillForm]] Fill forms automating input boxes, drop down selections, checkboxes, radiobuttons, etc. | #[[Demo-FillForm]] Fill forms automating input boxes, drop down selections, checkboxes, radiobuttons, etc. | ||
− | #[[Demo- | + | #[[XPATH|Demo-FillForm_XPath]] Use XPath to navigate through elements and attributes in an XML document |
#[[Demo-Filter]] Filter pictures for faster page loading | #[[Demo-Filter]] Filter pictures for faster page loading | ||
#[[Demo-Flash]] Automate flash applets | #[[Demo-Flash]] Automate flash applets | ||
#[[Demo-Frames]] Automate sites using HTML frames | #[[Demo-Frames]] Automate sites using HTML frames | ||
− | |||
#[[Demo-ImageDownload]] Download picture to local disc, take screenshots | #[[Demo-ImageDownload]] Download picture to local disc, take screenshots | ||
#[[Demo-ImageRecognition]] Automate e.g. a flash plugin by its graphical elements | #[[Demo-ImageRecognition]] Automate e.g. a flash plugin by its graphical elements | ||
#[[Demo-JavascriptDialog]] Handle pop-up dialogs | #[[Demo-JavascriptDialog]] Handle pop-up dialogs | ||
− | #[[Demo-JavaScriptMenu]] Navigate through JavaScript menus | + | <!--#[[Demo-JavaScriptMenu]] Navigate through JavaScript menus--> |
+ | #[[Demo-Keyword-Assert]] Asserts that a specific keyword appears on a web page | ||
#[[Demo-Loop-Csv-2-Web]] Fill textfile (CSV) data to web form | #[[Demo-Loop-Csv-2-Web]] Fill textfile (CSV) data to web form | ||
#[[Demo-OfflineDialogs]] Automates pop-up dialogs (macro runs on local HTML code) | #[[Demo-OfflineDialogs]] Automates pop-up dialogs (macro runs on local HTML code) | ||
Line 40: | Line 44: | ||
#[[Demo-WebPageDialog]] iMacros handles web page dialogs | #[[Demo-WebPageDialog]] iMacros handles web page dialogs | ||
#[[Demo-Web-Test]] Use macro for web testing | #[[Demo-Web-Test]] Use macro for web testing | ||
− | #[[Demo-Winclick]] Automate Java/Flash applets | + | #[[Parse Twitter Tweets]] Extract information from tweets |
+ | <!--#[[Demo-Winclick]] Automate Java/Flash applets--> | ||
== Batch Files == | == Batch Files == | ||
− | + | The iMacros Browser includes a command line interface, so it can be controlled via batch files. | |
#[[Example-Batchfile.bat]] | #[[Example-Batchfile.bat]] | ||
#[[Example-ErrorLevel]] | #[[Example-ErrorLevel]] | ||
#[[Tray-Example-Batchfile.bat]] | #[[Tray-Example-Batchfile.bat]] | ||
− | == ASP | + | == Task Scheduler == |
+ | |||
+ | To schedule a certain macro to run at a certain hour, please use the Windows Task Scheduler and the iMacros [[Command_Reference#Command_Line_Switches|command line interface]] (same commands as used in [[#Batch Files|Batch Files]].) | ||
+ | |||
+ | You can also [[VBS_Command_Line|call VBS scripts from the command line]]. | ||
+ | |||
+ | Related chapter: [[Web_Scripting#How_to_run_iMacros_unattended|How to run iMacros unattended]] | ||
+ | |||
+ | Related FAQ: [[Web_Testing#Q:_How_can_I_set_up_a_24_hours_a_day.2C_7_days_a_week_.28non-stop.29_operation_with_iMacros.3F|How can I set up a 24 hours a day, 7 days a week (non-stop) operation with iMacros?]] | ||
+ | |||
+ | == ASP == | ||
+ | |||
+ | An ASP sample project is included in the [https://www.imacros.net/download iMacros download]. It uses the [[iimRunner]] feature. | ||
+ | |||
+ | == ASP.NET == | ||
+ | |||
+ | An ASP.NET sample project is included in the [https://www.imacros.net/download 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. | ||
+ | |||
+ | == C# == | ||
+ | |||
+ | [[CSharp|C# sample projects]] are included in the [https://www.imacros.net/download 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 [[x64|64-bit version]] the 64-bit iMacros Scripting Interface is automatically used. | ||
+ | |||
+ | == C++ == | ||
+ | |||
+ | C++ sample projects are available [[CPP|here]]. | ||
+ | |||
+ | And [[CPP_Tutorial|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 [http://www.connectionstrings.com/ connection string] in the script. | |
− | + | #[[Database-2-Web.vbs|database-2-web.vbs]] Submit database information to a website. Shows how to query any database. | |
+ | #[[Extract-2-Database.vbs|extract-2-database.vbs]] Web scrape data into a database. | ||
+ | == Delphi == | ||
− | + | A step-by-step tutorial can be found here: [[Delphi]] | |
− | == | + | == Excel == |
+ | The iMacros Browser, IE, Firefox, and Chrome can be integrated with all Microsoft Office products (e. g. Excel, Access). Please see the [[Sample_Code#VBA|VBA]] section for example projects. | ||
− | + | == FoxPro == | |
− | + | Please see the [[FoxPro]] tutorial. | |
− | + | == Java == | |
− | == | + | Please see the user forum for an [https://forum.imacros.net/viewtopic.php?t=2703 Eclipse tutorial] and a [https://forum.imacros.net/viewtopic.php?f=6&t=7183 NetBeans tutorial]. |
− | + | == Javascript == | |
− | == Visual Basic | + | The regular Windows Scripting Interface can be used from within [[JavaScript]] and [[JScript]]. |
+ | |||
+ | Older versions of iMacros for Firefox ([[iMacros_for_Firefox_Legacy|version 8 and below]]) used to have a [[iMacros_for_Firefox_Legacy#Javascript_Scripting_Interface|built-in Javascript Scripting Interface]]. This is no longer supported by newer versions of Firefox (Firefox 56 and above) and has been removed from iMacros. | ||
+ | |||
+ | == Perl == | ||
+ | |||
+ | Please see the [[Perl]] tutorial. | ||
+ | |||
+ | == PHP == | ||
+ | |||
+ | Please see the [[PHP|PHP sample]]. | ||
+ | |||
+ | == Python == | ||
+ | |||
+ | Please see the [[Python]] tutorial. | ||
+ | |||
+ | == PowerShell == | ||
+ | |||
+ | Please see the [[PowerShell]] tutorial. | ||
+ | |||
+ | #[[self-test.ps1]] Run all iMacros demo macros and create a test report. | ||
+ | |||
+ | == Ruby == | ||
+ | |||
+ | Please see the [[Ruby]] tutorial. | ||
+ | |||
+ | == TCL == | ||
+ | |||
+ | 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. | ||
#[[Combine-Macros.vbs|combine-macros.vbs]] Shows how to create a custom error report log file | #[[Combine-Macros.vbs|combine-macros.vbs]] Shows how to create a custom error report log file | ||
#[[connect-to-ie.vbs]] Remote control Internet Explorer | #[[connect-to-ie.vbs]] Remote control Internet Explorer | ||
#[[connect-to-fx.vbs]] Remote control Mozilla FireFox | #[[connect-to-fx.vbs]] Remote control Mozilla FireFox | ||
+ | #[[connect-to-cr.vbs]] Remote control Google Chrome | ||
#[[connect-to-iimrunner.vbs]] Shows how to work with iimRunner.exe | #[[connect-to-iimrunner.vbs]] Shows how to work with iimRunner.exe | ||
− | #[[Database-2-Web.vbs|database-2-web.vbs]] Submit database information to a website | + | #[[Database-2-Web.vbs|database-2-web.vbs]] Submit database information to a website. Shows how to query any database. |
− | |||
#[[Extract-2-File.vbs|extract-2-file.vbs]] Web scrape data into a plain text file. | #[[Extract-2-File.vbs|extract-2-file.vbs]] Web scrape data into a plain text file. | ||
#[[Extract-2-Database.vbs|extract-2-database.vbs]] Web scrape data into a database. | #[[Extract-2-Database.vbs|extract-2-database.vbs]] Web scrape data into a database. | ||
Line 89: | Line 157: | ||
#[[Random-Numbers.vbs|random-numbers.vbs]] Fill an online form with random numbers. | #[[Random-Numbers.vbs|random-numbers.vbs]] Fill an online form with random numbers. | ||
#[[send-macro-code.vbs]] Directly send macro code to iMacros instance instead of calling locally stored macros. | #[[send-macro-code.vbs]] Directly send macro code to iMacros instance instead of calling locally stored macros. | ||
− | #[[ | + | #[[self-test.vbs]] Run all iMacros demo macros and create a test report. |
+ | #[[stresstest.vbs]] Run several iMacros instances in parallel. | ||
+ | #[[VBS_looping|Create loops with VBS]] Tutorial with screenshots | ||
+ | #[[Loop after Query or Login|Loop only parts of a macro]] Tutorial with screenshots | ||
− | Important: iMacros can | + | Important: iMacros can be controlled with the 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 | + | == VB.NET == |
− | + | VB.NET sample projects for Visual Studio 2003 and 2005 are included in the [https://www.imacros.net/download iMacros download].. The samples especially show the threading features of iMacros. You can run and control many browsers simultaneously. | |
− | + | == VBA == | |
− | + | The iMacros Browser, IE and Firefox can be integrated with all Microsoft Office products (e. g. Excel, Access): | |
− | + | #[[Excel_VBA Example Code|Excel-VBA-Submit-and-Extract]] (with screenshots) | |
− | #[[ | ||
#[[Excel-VBA-StockSearch]] | #[[Excel-VBA-StockSearch]] | ||
Line 109: | Line 184: | ||
Click here for some [[Recent_Project_Samples|recent project samples]] | Click here for some [[Recent_Project_Samples|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. |
Revision as of 07:14, 24 April 2019
Examples for using iMacros efficiently.
All macros and scripts listed here are included in the default installation of iMacros Samples (unless otherwise noted).
No vendor specific scripting language. iMacros does not use an awkward, proprietary vendor specific scripting language. The iMacros Browser, Internet Explorer (with iMacros for IE), 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. The basic usage is the same in every language.
Macros
iMacros macros are used to describe the page specific interaction.
- Demo-AJAX-Tree Move element of an AJAX tree view by drag & drop. No fixed coordinates required.
- Demo-ArchivePage Save the current page with custom file name
- Demo-Datasource Enter data from textfile (CSV) into web form
- Demo-DirectScreen Automate Java Calculator Applet
- Demo-Download Automate file downloads
- Demo-Draw Record mouse movements for e.g. java applets
- Demo-Extract Extract text, HTML code, links, tables
- Demo-ExtractAndFill Extract data and directly fill it into another web site
- Demo-ExtractRelative Use relative positioning for more easy extraction
- Demo-Extract-Table Extract complete table with one command and save data to text file
- Demo-Eval Test for value and time ranges in your macro and anything else that can be done with Javascript
- Demo-FillForm Fill forms automating input boxes, drop down selections, checkboxes, radiobuttons, etc.
- Demo-FillForm_XPath Use XPath to navigate through elements and attributes in an XML document
- Demo-Filter Filter pictures for faster page loading
- Demo-Flash Automate flash applets
- Demo-Frames Automate sites using HTML frames
- Demo-ImageDownload Download picture to local disc, take screenshots
- Demo-ImageRecognition Automate e.g. a flash plugin by its graphical elements
- Demo-JavascriptDialog Handle pop-up dialogs
- Demo-Keyword-Assert Asserts that a specific keyword appears on a web page
- Demo-Loop-Csv-2-Web Fill textfile (CSV) data to web form
- Demo-OfflineDialogs Automates pop-up dialogs (macro runs on local HTML code)
- Demo-OfflineExtract Extract data from web sites (macro runs on local HTML code)
- Demo-Print Print websites and PDF documents
- Demo-SaveAs Save Website in various formats
- Demo-SavePDF Download PDF files
- Demo-SaveTargetAs Download and save files using custom paths and file names
- Demo-Slideshow Loop through thumbnails
- Demo-Stopwatch Measure detailed website response times
- Demo-Tabs Make use of tabs
- Demo-Tagposition The relevance of the POS value in TAG commands
- Demo-TakeScreenshots Take screenshot of full page (not just the part visible in the browser)
- Demo-Upload Fill in file upload fields
- Demo-WebPageDialog iMacros handles web page dialogs
- Demo-Web-Test Use macro for web testing
- 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.
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?
ASP
An ASP sample project is included in the iMacros download. It uses the iimRunner feature.
ASP.NET
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.
C#
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++
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.
- database-2-web.vbs Submit database information to a website. Shows how to query any database.
- extract-2-database.vbs Web scrape data into a database.
Delphi
A step-by-step tutorial can be found here: Delphi
Excel
The iMacros Browser, IE, Firefox, and Chrome can be integrated with all Microsoft Office products (e. g. Excel, Access). Please see the VBA section for example projects.
FoxPro
Please see the FoxPro tutorial.
Java
Please see the user forum for an Eclipse tutorial and a NetBeans tutorial.
Javascript
The regular Windows Scripting Interface can be used from within JavaScript and JScript.
Older versions of iMacros for Firefox (version 8 and below) used to have a built-in Javascript Scripting Interface. This is no longer supported by newer versions of Firefox (Firefox 56 and above) and has been removed from iMacros.
Perl
Please see the Perl tutorial.
PHP
Please see the PHP sample.
Python
Please see the Python tutorial.
PowerShell
Please see the PowerShell tutorial.
- self-test.ps1 Run all iMacros demo macros and create a test report.
Ruby
Please see the Ruby tutorial.
TCL
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.
- combine-macros.vbs Shows how to create a custom error report log file
- connect-to-ie.vbs Remote control Internet Explorer
- connect-to-fx.vbs Remote control Mozilla FireFox
- connect-to-cr.vbs Remote control Google Chrome
- connect-to-iimrunner.vbs Shows how to work with iimRunner.exe
- database-2-web.vbs Submit database information to a website. Shows how to query any database.
- extract-2-file.vbs Web scrape data into a plain text file.
- extract-2-database.vbs Web scrape data into a database.
- extract-and-fill.vbs Web scrape data from one website and submit it to a second website.
- file-2-web.vbs Submit information from a text file to a website (Method 1)
- file-2-web-method2.vbs Submit information from a text file to a website (Method 2)
- get-exchange-rate.vbs Extract exchange rate from a website. Runs in tray.
- get-response-times.vbs Measure response times and use them in script.
- iimRunner_ASP.vbs Connect to iMacros via iimRunner, like when using ASP or ASP.NET
- random-numbers.vbs Fill an online form with random numbers.
- send-macro-code.vbs Directly send macro code to iMacros instance instead of calling locally stored macros.
- self-test.vbs Run all iMacros demo macros and create a test report.
- stresstest.vbs Run several iMacros instances in parallel.
- Create loops with VBS Tutorial with screenshots
- Loop only parts of a macro Tutorial with screenshots
Important: iMacros can be controlled with the 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
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.
VBA
The iMacros Browser, IE and Firefox can be integrated with all Microsoft Office products (e. g. Excel, Access):
- Excel-VBA-Submit-and-Extract (with screenshots)
- 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.