4

Could any one help me in creating a HTML DOM object using VB script. I have to navigate through a HTML form and enter value in the textbox or select a value from a drop down using vb script and HTML DOm functions.

I know that to create a XMl dom object we can use a below statement, so any statements simillar to below one is available to create a HTML DOM.

Set Xmlobj = CreateObject ("Microsoft.XMLDOm")

Set Htmlobj = CreateObject ("Microsoft.HtmlDom")  ' Is this avalibale when I tried it shows     error for object creattion, other workaround available.

2 Answers 2

2

There is no "HTMLDOM" object, since there is a lot more attached to HTML than to XML. It would take JavaScript handling, session handling, CSS handling, HTTP requests, cookie handling, caching etc to turn textual HTML into a meaningful in-memory document object.

If all that was implemented, you'd have a complete browser. Which is why there is no such COM object.

For your task could could use the Internet Explorer directly through COM automation:

Option Explicit

Dim IE, queryField

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

IE.Navigate "http://www.google.com"

While IE.Busy Or IE.readyState <> 4
     WScript.Sleep 100
Wend

Set queryField = GetFormFieldByName(IE.document, "q")

If Not queryField Is Nothing Then
    QueryField.value = "test"
    QueryField.form.submit
End If

WScript.Sleep 5000
IE.Quit
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Function GetFormFieldByName(Parent, FindName)
    Dim FormFields, FormField

    Set GetFormFieldByName = Nothing
    Set FormFields = Parent.getElementsByTagName("INPUT")

    For Each FormField In FormFields
        If UCase(FormField.Name) = UCase(FindName) Then
            Set GetFormFieldByName = FormField
            Exit For
        End If
    Next
End Function
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a Lot!!! one doubt, in this approach we are using the automation object model of internet explorer to create a IE object. And we are combining with HTML DOM properties and functions.My doubt is can we chain any object or property (of HTML DOm) with createdIEobject? My second doubt is why do we chain IE with document property and this 'document' propery or object used here is a HTML DOm or IEs automation object model.
The IE.document is exactly the same document object you see from JavaScript running inside the browser. With it you can perform any operation IE supports. That's why it's called "automation": you use an external script to remote control IE.
okay, I could understand that only using IE.document we can call other methods and properties of HTML DOM. But this term "document" here is it an object, method or property?
It's a property of the IE object. What difference does that make?
2
Set oDoc = CreateObject("HTMLFILE")

oDoc.write "<html><head><title></title></head><body><div id='div'>hello</div></body></html>"

Response.Write oDoc.getElementById("div").innerHTML 

--

WScript.Echo oDoc.getElementById("div").innerHTML 

Output: -

hello

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.