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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With