Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 651
  • Last Modified:

InternetExplorer automation using VBScript

Hi,

I need to fill a long online form with lots of data,so I want to do it programmatically using VBScript.
The form webpage initially has a login form, than you get to an index page (selecting one of several forms) and finally to the form page.

I can manage to automate the login access and navigation up to the form page, but
1) how can I retrieve the full HTML text of the form page (I need this because in order to match the form input box with the data I want to enter, I have to analyze the text surrounding each input box)
2) how can I submit a form that doesn't have a "submit" button (the form gets submitted when you click on a link that actually does "form.submit" in javascript). I tried oIE.document.all("form1").submit, but I get an error saying that the submit method doesn't exist.

This is the code I'm using (working, but I changed the real address/credentials with fake ones) to reach to the form:

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True
oIE.Navigate "www.someurl.it\somepage"
Do While oIE.Busy Or (oIE.READYSTATE <> 4)
    Wscript.Sleep 10
Loop

'login
If Not oIE.document.all("user") is nothing Then
 oIE.document.all("user").Value = "pippo"
 oIE.document.all("pass").Value = "baudo"
 oIE.document.all("submit").click
 Do While oIE.Busy Or (oIE.READYSTATE <> 4)
     Wscript.Sleep 10
 Loop
End If

'navigate to form A01
oIE.Navigate "www.someurl.it/somepage/index.asp?sez=A¶grafo=01"
Do While oIE.Busy Or (oIE.READYSTATE <> 4)
    Wscript.Sleep 10
Loop

'Now I see the form on the screen and I need to retrieve the full HTML source
0
lbertacco
Asked:
lbertacco
  • 4
  • 2
1 Solution
 
mvidasCommented:
Hi lbertacco,

For the html source, use:
 oIE.Document.Body.InnerHTML

For the submit part, hopefully someone else can help you with that, but have you tried something like
 oIE.Navigate "javascript:form.submit()"

Just a thought
Matt
0
 
lbertaccoAuthor Commented:
I'll try that. Can you also point me to a good online reference the InternetExplorer.Document object?
0
 
mvidasCommented:
As far as looking at the properties/methods, I open an MS office program, go to the VBA (alt-f11), and add a reference to "Microsoft HTML Object Library", and then Dim a variable as HTMLDocument (this works for other objects of the internetexplorer object too).  But you can see how to use all of the IE object, not just the document, at http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/objects/internetexplorer.asp
Matt
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
mvidasCommented:
From there (sorry, forgot to include this), you can see the document object at http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_document.asp
0
 
lbertaccoAuthor Commented:
Mmh, the innerHTML property doesn't return the orignal HTML but a bit reformatted (capitalized tags, removed quotes, reordered attributes).
Is there a way to obtain the ORIGINAL html code?
0
 
mvidasCommented:
Unfortunately, I don't think there is using the IE object, since that is how it is processed by the app.  You could try using the xmlhttp object, though you'll have to experiment with the logging in portion.  Perhaps once you log in with IE, and keep that object around, it may work for you:

Function GetWebText(ByVal vWebSite)
 Dim oXMLHTTP, vWebText, i
 Set oXMLHTTP = CreateObject("msxml2.xmlhttp")
 oXMLHTTP.Open "GET", vWebSite, False
 oXMLHTTP.send
 If (oXMLHTTP.readyState = 4) And (oXMLHTTP.Status = 200) Then
  vWebText = oXMLHTTP.ResponseText
  vWebText = Replace(vWebText, "&quot;", Chr(34))
  vWebText = Replace(vWebText, "&lt;", Chr(60))
  vWebText = Replace(vWebText, "&gt;", Chr(62))
  vWebText = Replace(vWebText, "&amp;", Chr(38))
  vWebText = Replace(vWebText, "&nbsp;", Chr(32))
  For i = 1 To 255
   vWebText = Replace(vWebText, "&#" & i & ";", Chr(i))
  Next
 End If
 GetWebText = vWebText
 Set oXMLHTTP = Nothing
End Function

You could also try the .Open line with the un/pw:

 oXMLHTTP.Open "GET", vWebSite, False, "username", "password"

But that is avoiding IE altogether (won't work for the forms you need to use).  Unfortunately, I don't believe there is a property of the IE object to get the original html.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now