Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a HTML DOM object for accessing HTML objects in a html form

Tags:

dom

vbscript

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.
like image 979
user1925406 Avatar asked Oct 27 '25 20:10

user1925406


2 Answers

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
like image 185
Tomalak Avatar answered Oct 31 '25 21:10

Tomalak


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

like image 23
Richard Lai Avatar answered Oct 31 '25 21:10

Richard Lai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!