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++.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Perl & iMacros: Problem passing variables

by manticor24 on Fri Feb 13, 2009 2: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 4:51 pm

Re: Perl & iMacros: Problem passing variables

by manticor24 on Mon Feb 16, 2009 10:02 am

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 4:51 pm

Re: Perl & iMacros: Problem passing variables

by manticor24 on Mon Feb 16, 2009 10:18 am

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;
    }
manticor24
 
Posts: 4
Joined: Thu Jun 05, 2008 4:51 pm

Re: Perl & iMacros: Problem passing variables

by Tech Support on Tue Feb 17, 2009 9:50 am

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")
User avatar
Tech Support
 
Posts: 5003
Joined: Tue Sep 20, 2005 12:25 pm

Re: Perl & iMacros: Problem passing variables

by manticor24 on Tue Feb 17, 2009 11:07 pm

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.)
manticor24
 
Posts: 4
Joined: Thu Jun 05, 2008 4:51 pm

Re: Perl & iMacros: Problem passing variables

by Kelicula on Mon Dec 15, 2014 9:00 am

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>
Kelicula
 
Posts: 7
Joined: Tue Oct 07, 2014 11:17 am


Return to Scripting and Command Line Interface

Who is online

Users browsing this forum: No registered users and 4 guests

-->