Retrieving Elements From a web Form

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
ShaneCl
Newbie
Posts: 13
Joined: Sun Apr 24, 2005 2:18 am
Location: Toowoomba - Aust

Retrieving Elements From a web Form

Post by ShaneCl » Sun Apr 24, 2005 3:22 am

I have been using a modified version of the code found under "Automate Web forms with IE" posted on the 10th of December

My question is How can I use the same process without using Set IE = CreateObject("InternetExplorer.Application") as Internet Explorer is already running and the correct web page is already displayed.

Original Code from Forum


VBSTART
Dim IE

Sub CreateIE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible=1
End Sub

Sub Navigate(URL)
IE.Navigate URL
do while IE.Busy
loop
End Sub

Sub KillIE
IE.Quit
Set IE = nothing
End Sub

Sub WebFormFill(fieldname,fieldvalue,submit)
Dim FormNr
Dim ItemNr
Dim TheForm

if IE.Document.All.Tags("FORM").Length = 0 then
MsgBox("No form found in page")
else
for FormNr = 0 to IE.Document.Forms.Length - 1
Set TheForm = IE.Document.Forms(FormNr)
for ItemNr = 0 to TheForm.Elements.Length - 1
if TheForm.Elements(ItemNr).Name = fieldname then
TheForm.Elements(ItemNr).Value = fieldvalue
If submit=1 then
TheForm.submit
end if
exit for
end if
next
next
end if
End Sub

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Sun Apr 24, 2005 7:06 am

You can't. GetObject lets you "get" an already running object, but, alas, Internet Explorer does not support it.
MJT Net Support
[email protected]

ShaneCl
Newbie
Posts: 13
Joined: Sun Apr 24, 2005 2:18 am
Location: Toowoomba - Aust

Post by ShaneCl » Tue Apr 26, 2005 11:34 am

Thanks for the reply, you have confirmed what I was begining to suspect.

and while I'm here

Thankyou for the great support you provide.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Apr 26, 2005 11:50 am

Actually, I've found a workaround to getting an already running IE object. This function enumerates IE windows. I've written this to find a running IE instance with the given URL. You could modify this if you're just looking for any old IE instance and have it stop when it finds the first one, or put each one in an array .. or whatever. This version finds the instance with the given URL. To test this open a copy of IE and navigate to http://www.mjtnet.com/ and then run this script. It will find the IE instance and navigate it to google.com:

VBSTART
Dim IE

Function GetIE(sURL)
GetIE = 0
set shellApp = createobject("shell.application")
for each w in shellApp.windows
if lcase(typename(w.document)) = "htmldocument" then
if w.LocationURL = sURL then
Set IE = w
GetIE = 1
end if
end if
next
set shellApp = nothing
End Function

Sub Navigate(sURL)
IE.Navigate sURL
do while IE.Busy
loop
End Sub
VBEND

VBEval>GetIE("http://www.mjtnet.com/"),success
If>success=1
VBRun>Navigate,http://www.google.com/
EndIf

Hope this helps.
MJT Net Support
[email protected]

ShaneCl
Newbie
Posts: 13
Joined: Sun Apr 24, 2005 2:18 am
Location: Toowoomba - Aust

Post by ShaneCl » Tue Apr 26, 2005 12:21 pm

Now didn't I just say you supply great support to your users

and this just proves it

Thanks Again

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