Using WebRecorder to build a macro

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
heneghan
Newbie
Posts: 6
Joined: Sun Mar 04, 2007 3:16 am

Using WebRecorder to build a macro

Post by heneghan » Tue Feb 05, 2008 8:04 pm

I want to use a macro to goto a webpage, conduct a search with parameters, click through to a summary page and then save the file to disk. I used webrecorder to build the macro but it hangs up once I have selected the radio button. Any help would be appreciated:

// Generated by MacroScript WebRecorder 2.01
// Recorded on Tuesday, February 5, 2008, at 12:44 PM
LibLoad>c:\program files\webrecorder\IEAuto.dll,hIE
If>hIE=0
MessageModal>Could not load IEAuto.dll, make sure it is in the path or edit the LibLoad line.
Goto>end_script
EndIf

//Move the mouse cursor out of harm's way to avoid causing mouseover events to interrupt
MouseMove>0,0

Let>delay=1

LibFunc>hIE,CreateIE,IE[1],0

LibFunc>hIE,Navigate,r,%IE[1]%,http://www.tc.gc.ca/aviation/applicatio ... hquery.asp
LibFunc>hIE,WaitIE,r,%IE[1]%
Wait>delay

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>FieldName={"txtFrom"}
Let>FieldValue={"2008/01/01"}
LibFunc>hIE,FormFill,r,%IE[1]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>FieldName={"lstFieldToSearch"}
Let>FieldValue={"Aircraft Model"}
LibFunc>hIE,FormFill,r,%IE[1]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>FieldName={"txtSearchText"}
Let>FieldValue={"s76"}
LibFunc>hIE,FormFill,r,%IE[1]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>TagValue={"http://www.tc.gc.ca/aviation/applicatio ... search.gif"}
LibFunc>hIE,ClickTag,r,%IE[1]%,str:FrameName,str:FormName,INPUT,SRC,str:TagValue

LibFunc>hIE,WaitIE,r,%IE[1]%
Wait>4

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>TagValue={"chkPrintTen:on"}
LibFunc>hIE,ClickTag,r,%IE[1]%,str:FrameName,str:FormName,INPUT,CHECKBOX,str:TagValue


// This is where the routine hangs up
//
Let>FrameName={""}
Let>FormName={"frmMain"}
Let>TagValue={"btnPrintPreview"}
LibFunc>hIE,ClickTag,r,%IE[1]%,str:FrameName,str:FormName,IMG,NAME,str:TagValue

libFunc>hIE,WaitNewIE,IE[2],0
libFunc>hIE,WaitIE,r,IE[2]

LibFunc>hIE,WaitIE,r,%IE[2]%
Wait>delay

LibFree>hIE
Label>end_script


//After running the script, I want to save the file as C:\files\cadors\summary.html
//and then close the window.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Feb 06, 2008 1:28 pm

It is "hanging" because nothing happens when IEAuto tries to click the btnPrintPreview button. And since the next part of the script waits for a new IE window and the button click did not have effect, the script will wait forever.

I'm not sure why ClickTag is not able to activate the Print Preview button, but there is a simple workaround. Just navigate to the location the button points to.

This script works:

Code: Select all

LibLoad>c:\program files\webrecorder\IEAuto.dll,hIE
If>hIE=0
MessageModal>Could not load IEAuto.dll, make sure it is in the path or edit the LibLoad line.
Goto>end_script
EndIf

//Move the mouse cursor out of harm's way to avoid causing mouseover events to interrupt
MouseMove>0,0

Let>delay=1

LibFunc>hIE,CreateIE,IE[1],0

LibFunc>hIE,Navigate,r,%IE[1]%,http://www.tc.gc.ca/aviation/applications/cadors/English/TextSearch/textsearchquery.asp
LibFunc>hIE,WaitIE,r,%IE[1]%
Wait>delay

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>FieldName={"txtFrom"}
Let>FieldValue={"2008/01/01"}
LibFunc>hIE,FormFill,r,%IE[1]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>FieldName={"lstFieldToSearch"}
Let>FieldValue={"Aircraft Model"}
LibFunc>hIE,FormFill,r,%IE[1]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>FieldName={"txtSearchText"}
Let>FieldValue={"s76"}
LibFunc>hIE,FormFill,r,%IE[1]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>TagValue={"http://www.tc.gc.ca/aviation/applications/cadors/English/images/search.gif"}
LibFunc>hIE,ClickTag,r,%IE[1]%,str:FrameName,str:FormName,INPUT,SRC,str:TagValue

LibFunc>hIE,WaitIE,r,%IE[1]%
Wait>4

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>TagValue={"chkPrintTen:on"}
LibFunc>hIE,ClickTag,r,%IE[1]%,str:FrameName,str:FormName,INPUT,CHECKBOX,str:TagValue

// This is where the routine hangs up
//
/*
Let>FrameName={""}
Let>FormName={"frmMain"}
Let>TagValue={"btnPrintPreview"}
LibFunc>hIE,ClickTag,r,%IE[1]%,str:FrameName,str:FormName,IMG,NAME,str:TagValue
*/
LibFunc>hIE,Navigate,r,%IE[1]%,javascript:Move(document.frmMain.btnPrintPreview);


libFunc>hIE,WaitNewIE,IE[2],0
libFunc>hIE,WaitIE,r,IE[2]

LibFunc>hIE,WaitIE,r,%IE[2]%
Wait>delay

LibFree>hIE
Label>end_script
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

heneghan
Newbie
Posts: 6
Joined: Sun Mar 04, 2007 3:16 am

Post by heneghan » Thu Feb 07, 2008 6:16 pm

Thanks so much for the workaround.

This final script goes to the page, completes the query, saves the result and emails it to me. Brilliant!!

Walter

_______________________

LibLoad>c:\program files\webrecorder\IEAuto.dll,hIE
If>hIE=0
MessageModal>Could not load IEAuto.dll, make sure it is in the path or edit the LibLoad line.
Goto>end_script
EndIf

//Move the mouse cursor out of harm's way to avoid causing mouseover events to interrupt
MouseMove>0,0

Let>delay=1

LibFunc>hIE,CreateIE,IE[1],0

LibFunc>hIE,Navigate,r,%IE[1]%,http://www.tc.gc.ca/aviation/applicatio ... hquery.asp
LibFunc>hIE,WaitIE,r,%IE[1]%
Wait>delay

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>FieldName={"txtFrom"}
Let>FieldValue={"2008/01/01"}
LibFunc>hIE,FormFill,r,%IE[1]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>FieldName={"lstFieldToSearch"}
Let>FieldValue={"Aircraft Operator"}
LibFunc>hIE,FormFill,r,%IE[1]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>FieldName={"txtSearchText"}
Let>FieldValue={"Canadian Helicopters"}
LibFunc>hIE,FormFill,r,%IE[1]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>TagValue={"http://www.tc.gc.ca/aviation/applicatio ... search.gif"}
LibFunc>hIE,ClickTag,r,%IE[1]%,str:FrameName,str:FormName,INPUT,SRC,str:TagValue

LibFunc>hIE,WaitIE,r,%IE[1]%
Wait>4

Let>FrameName={""}
Let>FormName={"frmMain"}
Let>TagValue={"chkPrintTen:on"}
LibFunc>hIE,ClickTag,r,%IE[1]%,str:FrameName,str:FormName,INPUT,CHECKBOX,str:TagValue

// This is where the routine hangs up
//
/*
Let>FrameName={""}
Let>FormName={"frmMain"}
Let>TagValue={"btnPrintPreview"}
LibFunc>hIE,ClickTag,r,%IE[1]%,str:FrameName,str:FormName,IMG,NAME,str:TagValue
*/
LibFunc>hIE,Navigate,r,%IE[1]%,javascript:Move(document.frmMain.btnPrintPreview);


libFunc>hIE,WaitNewIE,IE[2],0
libFunc>hIE,WaitIE,r,IE[2]

LibFunc>hIE,WaitIE,r,%IE[2]%
Wait>delay

LibFree>hIE
Label>end_script
//After running the script, I want to save the file as C:\files\cadors\summary.html
//and then close the window.

Wait>5
Press ALT
Release ALT
Wait>.5
Send>f
Wait>.5
Send>a
Send Character/Text>c:\files\cadors\Summary CHL.htm
Wait>1
Press ENTER
Wait>1
Press TAB
Wait>1
Press ENTER
Wait>1
;PlayWav>C:\Program Files\Microsoft Office\OFFICE11\MEDIA\chimes.wav
Press ALT
Wait>1
Send>f
Send>cc

Press ALT
Wait>1
Send>f
Send>cc

BlockInput>2
Wait>5

Let>SENDMAIL_STATUS=1
PlayWav>chimes.wav
Hour>hour
Minutes>minutes
Month>month
Day>day
Year>year

Let>me=[email protected]
Let>myname=CHL CADORs Summary
Let>recipients=[email protected];[email protected];
Let>subject=Year to Date CADORS Summary All CHL
Let>body=Here is the latest CADORS Summary for %hour%%minutes%_hrs_%day%_%month%.
Let>attachments=c:\files\cadors\summary CHL.htm
SMTPSendMail>recipients,smtp.telus.net,me,myname,subject,body,attachments
//

heneghan
Newbie
Posts: 6
Joined: Sun Mar 04, 2007 3:16 am

Post by heneghan » Thu Feb 07, 2008 6:56 pm

One more thing:

Right now I have set the start date for the query as 2008/1/1. Is it possible to add code that sets the start date to be, say 30 days prior to whatever date TODAY is? That would be even better.

Walter

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Feb 07, 2008 8:16 pm

Of course:

VBSTART
VBEND
VBEval>Year(date+30),yyyy
VBEval>Month(date+30),mm
VBEval>Day(date+30),dd
Let>startdate=%yyyy%/%mm%/%dd%
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

heneghan
Newbie
Posts: 6
Joined: Sun Mar 04, 2007 3:16 am

Post by heneghan » Thu Feb 07, 2008 9:49 pm

Perfect, you rock!!

Thanks

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts