FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   Add to FavoritesAdd to Favorites  * Code Snippets
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    RSS Get RSS Feed  


Automate web forms with IE

 
Post new topic   Reply to topic    Macro Scheduler and Windows Automation Forum Index -> Scripts and Tips
View previous topic :: View next topic  
Author Message
Marcus Tettmar
Site Admin


Joined: 19 Sep 2002
Posts: 5640
Location: Dorset, UK
Reputation: 1391
votes: 58

PostPosted: Fri Dec 10, 2004 12:00 am    Post subject: Automate web forms with IE Reply with quote

Contributed By: Marcus Tettmar mtettmar@mjtnet.com
Submitted On: 10/12/04

This is a "RoboForm" style script.  The Navigate function opens up a web page in IE.  The WebFormFill function then takes a field name and a value and sets the field on that web page with the value.  If submit is set to 1 it also submits the form.  This example automates the contact form at mjtnet.com:

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

'This function extracts text from a specific tag by name and index
'e.g. TABLE,0 (1st Table element) or P,1 (2nd Paragraph element)
'set all to 1 to extract all HTML, 0 for only inside text without HTML
Function ExtractTag(TagName,Num,all)
  dim t
  set t = IE.document.getElementsbyTagname(Tagname)
  if all=1 then
    ExtractTag = t.Item(Num).outerHTML
  else
    ExtractTag = t.Item(Num).innerText
  end if
End Function

VBEND

VBRun>CreateIE
VBRun>Navigate,http://www.mjtnet.com/contact.htm
Wait>1
VBRun>WebFormFill,name,Marcus,0
VBRun>WebFormFill,email,marcus.tettmar@mjtnet.com,0
VBRun>WebFormFill,mphone,1234,0
VBRun>WebFormFill,msubject,Macro Scheduler Pro,0
VBRun>WebFormFill,messagebody,Is a superb Product!,0
VBRun>WebFormFill,mver,7.3,1

Ask>All done - shall I close IE now?,r
If>r=YES
  VBRun>KillIE
endif



Did this message help you? If so please reward the poster with Reputation Points? Reward Points
Back to top
View user's profile Send private message Visit poster's website Facebook ID
fightcancer
Pro Scripter


Joined: 15 Apr 2005
Posts: 115

Reputation: 54.1

PostPosted: Mon Jan 21, 2013 2:59 am    Post subject: Reply with quote

I can't get this script to run any more.
_________________
Why is the richest nation ever 2nd to last in childhood poverty (among developed nations), 49th in literacy, 37th in general health, 41st in infant mortality?

Did this message help you? If so please reward the poster with Reputation Points? Reward Points
Back to top
View user's profile Send private message
Marcus Tettmar
Site Admin


Joined: 19 Sep 2002
Posts: 5640
Location: Dorset, UK
Reputation: 1391
votes: 58

PostPosted: Mon Jan 21, 2013 1:18 pm    Post subject: Reply with quote

The code is valid but the example works against a web page which no longer exists. So it won't run without modification. The VBScript code can be used on other pages.

In any case this is very old and superseded by WebRecorder and the native IE functions.
_________________
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Did this message help you? If so please reward the poster with Reputation Points? Reward Points
Back to top
View user's profile Send private message Visit poster's website Facebook ID
Display posts from previous:    View previous topic :: View next topic  
Post new topic   Reply to topic    Macro Scheduler and Windows Automation Forum Index -> Scripts and Tips All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group