Submitting a Web Form without WebRecorder

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Satch
Newbie
Posts: 11
Joined: Wed Mar 30, 2005 3:51 pm

Submitting a Web Form without WebRecorder

Post by Satch » Fri Jan 20, 2006 4:22 pm

Hi, I'm trying to use VBscript to fill and submit a seemingly simple Web form without using WebRecorder. I'm able to fill the form (it takes three items of data: last name, first name and e-mail address), but I am unable to submit the form.

I'm aware of the discussions of form-submission issues in topics http://www.mjtnet.com/forum/viewtopic.php?t=1368, http://www.mjtnet.com/forum/viewtopic.php?t=1390 and http://www.mjtnet.com/forum/viewtopic.php?t=2294.

Although I've tried the script from http://www.mjtnet.com/forum/viewtopic.php?t=1461 to no avail, the script I'm actually using (reproduced below) is from http://www.mjtnet.com/forum/viewtopic.php?t=1390.

My understanding is that the code below is designed to take care of the issue that arises when there's an object named SUBMIT on the page.

Unfortunately, the page I'm trying to automate is password-protected, so you won't be able to visit the real one, but I provide below the revealed HTML and I can e-mail the file "Mailshell - Check Mail Address Book.mht" (a single-file Web Archive file) to the support address, which, if placed on the "C:" drive of the computer testing the script above, should give an indication whether the form is being submitted or not (when it fails to submit, the filled fields remain filled; when it submits, the filled fields become empty; placing the cursor in any of the fields and pressing ENTER will manually submit the form, but it's completely impractical to script that physical action because the number of tabs to reach the fields changes from time to time).

Thanks for any help you can give!!

--Satch



VBSTART
Dim IE()
Dim MaxIEObjects

Function CreateIE
MaxIEObjects = MaxIEObjects + 1
ReDim preserve IE (MaxIEObjects)
Set IE(MaxIEObjects) = CreateObject("InternetExplorer.Application")
IE(MaxIEObjects).Visible=1
CreateIE = MaxIEObjects
End Function

Sub Navigate(IEInst,frame,URL)
if frame="" then
IE(IEInst).Navigate URL
else
on error resume next
dim err
err = 0
err = IE(IEInst).Document.Frames.length
if err = 0 then
IE(IEInst).Navigate URL
exit sub
end if
on error goto 0
dim frameNr
dim frameFound
frameFound = 0
if IE(IEInst).Document.Frames.Length > 0 then
for frameNr = 0 to IE(IEInst).Document.Frames.Length - 1
if IE(IEInst).Document.Frames(frameNr).name = frame then
IE(IEInst).Document.Frames(frameNr).navigate URL
frameFound = 1
exit for
end if
next
end if
if frameFound = 0 then
IE(IEInst).Navigate URL
end if
end if
do while IE(IEInst).Busy
loop
End Sub

Sub KillIE(IEInst)
IE(IEInst).Quit
Set IE(IEInst) = nothing
End Sub

Sub DoForm(TheForm,fieldname,fieldvalue,submit)
Dim ItemNr
for ItemNr = 0 to TheForm.Elements.Length - 1
if TheForm.Elements(ItemNr).Name = fieldname then
TheForm.Elements(ItemNr).Value = fieldvalue
If submit=1 then
Dim SubItems
Dim FoundSubmitButton
FoundSubmitButton = 0
for SubItems = 0 to TheForm.Elements.Length - 1
if UCase(TheForm.Elements(SubItems).Name) = "SUBMIT" then
if UCase(TheForm.Elements(SubItems).TYPE) = "SUBMIT" then
TheForm.Elements(SubItems).Click
FoundSubmitButton = 1
Exit For
end if
end if
next
if FoundSubmitButton = 0 then
TheForm.submit
end if
end if
exit for
end if
next
End Sub

Sub FormFill(IEInst,frame,fieldname,fieldvalue,submit)
Dim FormNr
Dim TheForm
if frame="" then
if IE(IEInst).Document.All.Tags("FORM").Length > 0 then
for FormNr = 0 to IE(IEInst).Document.Forms.Length - 1
Set TheForm = IE(IEInst).Document.Forms(FormNr)
DoForm TheForm,fieldname,fieldvalue,submit
Set TheForm = nothing
next
end if
else
dim frameNr
dim frameFound
frameFound = 0
if IE(IEInst).Document.Frames.Length > 0 then
for frameNr = 0 to IE(IEInst).Document.Frames.Length - 1
if IE(IEInst).Document.Frames(frameNr).name = frame then
if IE(IEInst).Document.frames(frame).Document.All.Tags("FORM").Length > 0 then
for FormNr = 0 to IE(IEInst).Document.frames(frame).Document.Forms.Length - 1
Set TheForm = IE(IEInst).Document.frames(frame).Document.Forms(FormNr)
DoForm TheForm,fieldname,fieldvalue,submit
Set TheForm = nothing
next
end if
frameFound = 1
exit for
end if
next
end if
if frameFound = 0 then
if IE(IEInst).Document.All.Tags("FORM").Length > 0 then
for FormNr = 0 to IE(IEInst).Document.Forms.Length - 1
Set TheForm = IE(IEInst).Document.Forms(FormNr)
DoForm TheForm,fieldname,fieldvalue,submit
Set TheForm = nothing
next
end if
end if
end if
do while IE(IEInst).Busy
loop
End Sub

Function ExtractTag(IEInst,TagName,Num,all)
dim t
set t = IE(IEInst).document.getElementsbyTagname(Tagname)
if all=1 then
ExtractTag = t.Item(Num).outerHTML
else
ExtractTag = t.Item(Num).innerText
end if
End Function

VBEND

Let>delay=1.5
VBEval>CreateIE,IE[0]
VBRun>Navigate,%IE[0]%,,C:\Mailshell - Check Mail Address Book.mht
Wait>delay
VBRun>FormFill,%IE[0]%,,lname,%LastName%,0
VBRun>FormFill,%IE[0]%,,fname,%FirstName%,0
VBRun>FormFill,%IE[0]%,,email,%Addr%,1





HTML:




Mailshell - Check Mail: Address Book








Hello equestrianSign Out




 
Spam Filtering
Check Mail
Compose
Options
Folders
Address Book
Help


 Contacts

Forwarding Addresses



 

 All - A
B
C
D

E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
- Groups
showing 1 - 1 of 1
Last NameFirst NameEmail 




Doe
John
[email protected]
EditDelete

Import Address Bookshowing 1 - 1 of 1
Page: 1






About Us
Tell a Friend
Privacy Policy
Terms of Service
Rewards Program
Help


Copyright © 2005 Mailshell.com All Rights Reserved.


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

Post by Marcus Tettmar » Fri Jan 20, 2006 4:32 pm

Hi,

It works for me!

I just copied your html to a new file. Modified the navigate line accordingly, ran the script and it filled the form and submitted it. Of course that results in a 404 since the form action does not exist on my machine.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Satch
Newbie
Posts: 11
Joined: Wed Mar 30, 2005 3:51 pm

Re: Submitting a Web Form without WebRecorder

Post by Satch » Fri Jan 20, 2006 5:04 pm

Thanks. I guess the local copy doesn't present the same problem. I've just sent the address/info for the real live web page in an e-mail to [email protected] in a response re: ticket number 488499.

The form on the real page truly will not submit.

How bewildering (and fascinating).

Any pointer you can give will be welcome.

Thanks!! I'm a loyal fan.

--Satch

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

Post by Marcus Tettmar » Fri Jan 20, 2006 5:27 pm

Hi,

Yes, in real life the form refused to submit. I got round it instead by running the click method of the Add button directly. Add this code into your VBSTART/VBEND block:


Function ClickIt(IEInst,form,field)
IE(IEInst).Document.forms(form).elements(field).click
End Function

Then after filling the form add this:

VBEval>ClickIt(%IE[0]%,0,"addEntry"),nul
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Satch
Newbie
Posts: 11
Joined: Wed Mar 30, 2005 3:51 pm

Post by Satch » Fri Jan 20, 2006 5:45 pm

simple + effective = beautiful

You are a scientist!

Thanks!!

--Satch

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