Advanced Web Browser Automation

21
Advanced Commands

description

Advanced Web Browser Automation

Transcript of Advanced Web Browser Automation

Page 1: Advanced Web Browser Automation

Advanced Commands

Page 2: Advanced Web Browser Automation

Advanced Commands

After visually recording the main parts of the macro, enhance and fine-tune the macro by editing it.

All macros are simple text files

File structure and commands fully documented

Page 3: Advanced Web Browser Automation

Macro in a Notepad File:

Page 4: Advanced Web Browser Automation

The recorded macro is stored in an easy to read text file (file ending: ".iim") which can be easily edited.

To edit a macro go to edit tab present on the left hand side of the browser, next to play and record and press edit macro button.

The default editor for editing Internet Macros is "Windows Notepad" (notepad.exe).

You can use another editor by changing the default editor in EDIT tab > click OPTIONS > PATHS tab.

If the macro has the name “mymacro", the corresponding text file is called “mymacro.iim".

Editing Macros:

Page 5: Advanced Web Browser Automation

Editing Macros Screenshot:

Page 6: Advanced Web Browser Automation

TOP 5 reasons to edit a macro

Edit typos made during recording

Insert Variables

Insert tags for response time measurements

Replace Session IDs with “*”

Copy & Paste several macros together or split macros in parts.

Page 7: Advanced Web Browser Automation

The link of some web sites change each time you visit them. This is because they create links with a "session id" which is different each time you log in.

Solution 1: Try a different ClickMode

Solution 2: Edit the macro manually after you recorded it and replace the ID (or any other changing part of the string) with "*".

Example: The command line:TAG POS=1 TYPE=AREAATTR=HREF:https://overture.com/s/index.jhtml;$sessionid$tzut78ZUZTIU67$&%

can be written as: TAG POS=1 TYPE=AREA ATTR=HREF:*index.jhtml*

Session IDs

Page 8: Advanced Web Browser Automation

Built-in variables These variables are used to define certain properties of the macro

behavior For example the macro timeout value SET !TIMEOUT 33.

User-defined Variables These variables are created at run time by the command line "-

var_MYVAR <value>". For Example -var_ITEM 15 creates the variable {{ITEM}} and gives it

the value 15. These variables can be part of ANYTHING inside the macro. In addition to routine tasks of opening and saving web pages,

macros can be used for more complicated tasks. For example, extracting data from one website and inserting it into another.

Two kinds of Variables:

Page 9: Advanced Web Browser Automation

Built-in Variables

SET !TIMEOUT 33 Defines new timeout value

SET !ERRORCONTINUE (YES/NO) Tells IM to ignore errors and continue

SET !REPLAYSPEED (FAST/MEDIUM/SLOW)

SET !FILELOG c:\mylog.txt Sets a specific log file name for the current macro

SET !EXTRACTADD {{!URLCURRENT}} Contains the current page URL {{…}} are used when the value of the variable is used

See user manual for a list of all built-in variables

Page 10: Advanced Web Browser Automation

Getting Data to a website

Page 11: Advanced Web Browser Automation

You can submit different information to the same Web page using Internet Macro.

The data source can be in two different formats: Either a text file with a list of variables and their values (“ini file

style”) A comma separated text file (CSV format) which can be generated

by Microsoft Excel and many other applications. The “List of variables" format is recommend if you have many

different variables (for example detailed address data or test of one user).

The CSV format is most appropriate for use with a few variables with many different values (for example a long list of user accounts that you want to submit to a website).

You can link to any CSV or List of variable file by using the statement in the macro:

CMDLINE !DATASOURCE mydata.txt

Submitting Data to Websites:

Page 12: Advanced Web Browser Automation

A CSV file looks like this: “FIRST NAME" , “LAST NAME" , “AGE“ “Andrew", “Smith", “23" “John”, “Rafols”, “39” “Ann”, “Schwarz”, “30”

Variables in the macro:{{!COL1}}, {{!COL2}}, {{!COL3}}

A “List of variables“ file looks like this:

[iOpus] FirstName=Andrew LastName=Smith Age=23

Variables in the macro: {{FirstName}}, {{LastName}}, {{Age}}

CSV and Variable Files

Page 13: Advanced Web Browser Automation

Demo: Submit Data to Website

Take a list of ISBN numbers from a file and search for them at Amazon.com

0970436300 0471430218 0471201006 0471232815 0131421891

Take a list of keywords and search for them on Google.com

Page 14: Advanced Web Browser Automation

Getting Data from web pages

Page 15: Advanced Web Browser Automation

Getting data from the Web Page

Save web page Downloading file PRINT EXTRACT command More specialized commands:

“Save Target As”, “Save Picture As” Events

In general, getting data from websites is more complicated than submitting data, as there any many forms in which the data is made available.

Internet Macros offers commands for each situation:

Page 16: Advanced Web Browser Automation

Web Data Extraction

TAG…. EXTRACT=…

Page 17: Advanced Web Browser Automation

Internet Macros can extract data from Web sites.

Open the site of your interest and start recording.

Click on the EXTRACT DATA button while in recording mode to bring up the extraction wizard.

The EXTRACT button is only available in the iMacros Browser but not in the IE Plug-In.

Extracting Data:

Page 18: Advanced Web Browser Automation

Open the Extraction Wizard.

In the browser window select the text that you want to extract.

Click the "Suggest" Button.

Click TEST to test run the extraction.

If you are satisfied with the result, click ADD to add the EXTRACT statement to the macro.

If you extract a complete table, the table data is automatically converted into comma-separated data

Defining which Data to Extract:

Page 19: Advanced Web Browser Automation

Data Extraction Wizard

Page 20: Advanced Web Browser Automation

There are three ways to save extracted data:

Built-in SAVEAS feature: You can use the SAVEAS TYPE=EXTRACT command inside a

macro. If several EXTRACT commands are used within one macro, the

content is appended to the file.

Reuse in macro using the {{!EXTRACT}} variable

Saving the data via the Internet Macros Scripting Interface: When you run the macro from a script you can return the data to the

script and save it with whatever method or format you prefer. For example, you can save it to a text file or even directly to a

database.

How to Store Extracted Information

Page 21: Advanced Web Browser Automation

Demo: Extract Data from Website

Create a price comparison engine: Take a list of ISBN numbers from a file and search for them at Amazon.com. Then save them in a CSV file with two columns (1st column: ISBN number, 2nd column: Price in US$)

0970436300 0471430218 0471201006 0471232815 0131421891