Perl & iMacros: Problem passing variables

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
manticor24
Posts: 4
Joined: Thu Jun 05, 2008 11:51 pm

Perl & iMacros: Problem passing variables

Post by manticor24 » Fri Feb 13, 2009 9:55 pm

This is my first time combining iMacros with the scripting interface, and I am using Perl. The macro works just fine when I run it alone in Firefox (using the !DATASOURCE and !COLn variables), but I need to have Perl control it so that I can log which entries fail to work. (That way I don't have to babysit the macro, which defeats the purpose of iMacros in the first place...)

I've wrapped the macro in a Perl "for" loop, reading from the same file. But whenever it runs, I see iMacros enter "__ undefined __" into the form fields.

At the same time, Perl generates this warning:

Code: Select all

Win32::OLE(0.1709) error 0x80020003: "Member not found" in PROPERTYPUT "Visible" at imacro.pl line 6, <DATA> line 68
So here's my code, taken almost line for line from the Wiki. What am I doing wrong?

Code: Select all

#!/usr/bin/perl -w
#use strict;
use Win32::OLE;

$b = Win32::OLE->new('imacros') or die "Iopus could not be started by Win32:OLE\n";
$b->{Visible} = 1;
$b->iimInit("-fx");

# Calling a macro
my $macro = "ae_robot_PERL.iim";

open(DATA,"../Documents/iMacros/Datasources/accounts.csv") or die $!;

for (my $n = 1; my $line = <DATA>; $n++){
	chomp($line);
	next unless $n >= 68;
	my ($client,$account,$ae,$userid) = split(m/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/,$line);
	#$b->iimSet("-loop",$n);
	$b->iimSet("-var_client",$client);
	$b->iimSet("-var_account",$account);
	$b->iimSet("-var_ae",$ae);
	$b->iimSet("-var_userid",$userid);
	$b->iimPlay($macro);
	&err ($n,$client,$account,$ae,$userid,$macro);

	# FOR TESTING PURPOSES ONLY
	if ($n == 68){
		$b->iimExit();
		die;
	}
}

$b->iimExit();

########################################################################
# Get the last message reported from Iopus upon macro completion status#
########################################################################
sub err {
	my $responsecode = $b->iimGetLastError();
	my ($n,$client,$account,$ae,$userid,$macro) = @_;

	open (LOG,">>./imacrolog.csv") or die $!;
	if ($responsecode =~ /completed/) {
		print("Success, line $n, Message:$responsecode\n");
		print LOG "SUCCESS, line $n,$client,$account,$ae,$userid";
	} else {
		print("Failure, line $n, Message:$responsecode\n");
		print LOG "FAIL, line $n,$client,$account,$ae,$userid";
	}
	close LOG;
}
My macro (which, again, works outside of the scripting interface!):

Code: Select all

VERSION BUILD=6111228 RECORDER=FX
TAB T=1
SET !REPLAYSPEED Fast
URL GOTO=https://urlredacted.com/
TAG POS=1 TYPE=DIV ATTR=ID:ctl00_header_mnuMainMenu_mnuAccounts
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:aspnetForm ATTR=ID:ctl00_main_cgAccountInfo_filterInput CONTENT={{client}}
TAG POS=1 TYPE=INPUT:BUTTON FORM=ID:aspnetForm ATTR=ID:ctl00_main_cgAccountInfo_filterGo
TAG POS=1 TYPE=SPAN ATTR=ID:ctl00_main_cgAccountInfo_r_*_c_ServiceLevelID_label&&TXT:Premium
TAG POS=R-1 TYPE=SPAN ATTR=TXT:{{client}}

TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:aspnetForm ATTR=ID:ctl00_main_cgAccountInfo_filterInput CONTENT={{account}}
TAG POS=1 TYPE=INPUT:BUTTON FORM=ID:aspnetForm ATTR=ID:ctl00_main_cgAccountInfo_filterGo
WAIT SECONDS=1
TAG POS=1 TYPE=SPAN ATTR=TXT:{{account}}

TAG POS=1 TYPE=DIV ATTR=ID:ctl00_main_mnuAccountManagement_mnuMenu_mnuEnterpriseAccountUsers
TAG POS=1 TYPE=SELECT FORM=NAME:aspnetForm ATTR=ID:ctl00_main_lstAvailableUsers CONTENT=%{{userid}}
TAG POS=1 TYPE=INPUT:BUTTON FORM=ID:aspnetForm ATTR=ID:ctl00_main_btnAdd
TAG POS=1 TYPE=SELECT FORM=NAME:aspnetForm ATTR=ID:ctl00_main_lstSelectedUsers CONTENT=%{{userid}}
TAG POS=1 TYPE=SELECT FORM=NAME:aspnetForm ATTR=ID:ctl00_main_dlResponsibility CONTENT=%1
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:aspnetForm ATTR=ID:btnPrimaryAE CONTENT=YES
TAG POS=1 TYPE=INPUT:BUTTON FORM=ID:aspnetForm ATTR=ID:ctl00_main_btnSave

WAIT SECONDS=3
CLICK X=213 Y=240
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:aspnetForm ATTR=ID:{{ae}} CONTENT=100
TAG POS=1 TYPE=SELECT ATTR=ID:ctl00_main_CalendarEffectiveDate_months CONTENT=%11
TAG POS=1 TYPE=SELECT ATTR=ID:ctl00_main_CalendarEffectiveDate_years CONTENT=%2008
TAG POS=1 TYPE=SPAN ATTR=ID:ctl00_main_CalendarEffectiveDate_span_27
TAG POS=1 TYPE=INPUT:BUTTON FORM=ID:aspnetForm ATTR=ID:ctl00_main_btnInsert


TAG POS=1 TYPE=DIV ATTR=ID:ctl00_header_mnuBreadCrumb_mnuCustomer
WAIT SECONDS=2
TAG POS=1 TYPE=DIV ATTR=ID:ctl00_header_mnuBreadCrumb_mnuCustomer
manticor24
Posts: 4
Joined: Thu Jun 05, 2008 11:51 pm

Re: Perl & iMacros: Problem passing variables

Post by manticor24 » Mon Feb 16, 2009 5:02 pm

Does anybody out there know Perl? I feel lost, and so alone... :(

How about this?! You don't have to know Perl to know the iMacros scripting interface, right? Does it look like I'm using the correct syntax there?

Or what about my iMacros code? Is it possible I've named the variable incorrectly?

Please PLEASE help me!
manticor24
Posts: 4
Joined: Thu Jun 05, 2008 11:51 pm

Re: Perl & iMacros: Problem passing variables

Post by manticor24 » Mon Feb 16, 2009 5:18 pm

Ok, I was thinking that the warning that Perl was generating was probably my main problem, but I've commented out the line "$b->{Visible} = 1;" which seems to have stopped the warning from occurring. Which is just as well, I don't know why it was in the example script, but it doesn't seem to be doing anything helpful, and there's no documentation to explain it. (Even changing it to $b->{Visible} = 0; does nothing that I can see.)

So, it's not a problem in the Win32::OLE interface. I also know that Perl is reading the data file "accounts.csv" just fine because it's logging the errors with complete data (as opposed to "undefined" values that I'm seeing entered into the forms).

Code: Select all

#!/usr/bin/perl -w
    use strict;
    use Win32::OLE;

    $b = Win32::OLE->new('imacros') or die "Iopus could not be started by Win32:OLE\n";
    #$b->{Visible} = 1;
    $b->iimInit("-fx");

    # Calling a macro
    my $macro = "ae_robot_PERL.iim";

    open(DATA,"../Documents/iMacros/Datasources/accounts.csv") or die $!;

    for (my $n = 1; my $line = <DATA>; $n++){
       chomp($line);
       next unless $n >= 68;
       my ($client,$account,$ae,$userid) = split(m/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/,$line);
       #$b->iimSet("-loop",$n);
       $b->iimSet("-var_client",$client);
       $b->iimSet("-var_account",$account);
       $b->iimSet("-var_ae",$ae);
       $b->iimSet("-var_userid",$userid);
       $b->iimPlay($macro);
       &err ($n,$client,$account,$ae,$userid,$macro);

       # FOR TESTING PURPOSES ONLY
       if ($n == 68){
          $b->iimExit();
          die;
       }
    }

    $b->iimExit();

    ########################################################################
    # Get the last message reported from Iopus upon macro completion status#
    ########################################################################
    sub err {
       my $responsecode = $b->iimGetLastError();
       my ($n,$client,$account,$ae,$userid,$macro) = @_;

       open (LOG,">>./imacrolog.csv") or die $!;
       if ($responsecode =~ /completed/) {
          print("Success, line $n, Message:$responsecode\n");
          print LOG "SUCCESS, line $n,$client,$account,$ae,$userid";
       } else {
          print("Failure, line $n, Message:$responsecode\n");
          print LOG "FAIL, line $n,$client,$account,$ae,$userid";
       }
       close LOG;
    }
User avatar
Tech Support
Posts: 4948
Joined: Tue Sep 20, 2005 7:25 pm
Contact:

Re: Perl & iMacros: Problem passing variables

Post by Tech Support » Tue Feb 17, 2009 4:50 pm

Please try again with iMacros V6.30.

It seems there was a bug with the old iimSet ("-var_name", "value") syntax, which is fixed now. But I still recommend to use the new syntax instead: iimSet ("name", "value")
manticor24
Posts: 4
Joined: Thu Jun 05, 2008 11:51 pm

Re: Perl & iMacros: Problem passing variables

Post by manticor24 » Wed Feb 18, 2009 6:07 am

Thank you much! That explains my trials and tribulations. I have installed the new version and gotten a test script to work with iMacros browser. (Firefox apparently still needs to be updated.)
Kelicula
Posts: 7
Joined: Tue Oct 07, 2014 6:17 pm

Re: Perl & iMacros: Problem passing variables

Post by Kelicula » Mon Dec 15, 2014 4:00 pm

I have also found it easy to include native perl variables in macro code eg:

Code: Select all

(my $name = "James Smith") =~ s/ /<SP>/g;
my $macro = qq{
TAG POS=1 TYPE=INPUT:TEXT ATTR=CLASS:first-name CONTENT=$name
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=TXT:Submit
};
$bh->iimPlayCode($macro);
Just be sure to filter out the spaces and/or newlines to appropriate iMacros syntax ie: <SP> or <BR>
Post Reply