|
-
Jun 24th, 2005, 01:14 PM
#1
RESOLVED: MSHTML - trying to get element collection
I am working on a project where I need to grab all elements of an HTML form via code. I am using a reference to MSHTML and the webbrowser control
I can get the document object fine, and get the form as well. The problem is when I try to get the elements of the form.
MSHTML is kind of weird because its from COM and was ported over to .NET by MS. It has TONS of interfaces and classes in it (so many my intellisense slows down when im using it)
Many of the interfaces and classes point to the same objects though.
I grab the form and put it in a MSHTML.HTMLFormElement interface (or the MSHTML.HTMLFormElementClass class, they both reference equal eachother)
the HTMLFormElement interface has an elements property, which should return the forms elements, but instead it just is a reference back to the form itself...
The only way I am able to grab elements currently is by using
HTMLFormElement.Item("elementname")
but since I wont know the element names, I need to get the collection of them, and output their name/value pairs
I don't think many people have worked with these objects on here.. but im sort of at a stand still.. so I figured I would post
Last edited by kleinma; Jun 24th, 2005 at 02:02 PM.
-
Jun 24th, 2005, 02:02 PM
#2
Re: MSHTML - trying to get element collection
I guess this is resolved, but I am open to any other input
I resolved this using the following code:
VB Code:
Dim IWebDocument As HTMLDocument
Dim IWebForm As HTMLFormElement
Dim IInputElement As HTMLInputElement
Dim IWebElements As IHTMLElementCollection
Dim ISelectElement As HTMLSelectElement
Dim ITextAreaElement As HTMLTextAreaElement
ListBox1.Items.Clear()
'GET DOCUMENT
IWebDocument = CType(wb.Document, HTMLDocument)
'GET FORM
IWebForm = CType(IWebDocument.forms.item(, 0), HTMLFormElement)
'GET INPUT ELEMENTS
IWebElements = IWebForm.getElementsByTagName("input")
For Each IInputElement In IWebElements
ListBox1.Items.Add(IInputElement.name & " - " & IInputElement.id & " - " & IInputElement.value & " - " & IInputElement.type & " - " & IInputElement.checked)
Next
'GET COMBOBOXES
IWebElements = IWebForm.getElementsByTagName("select")
For Each ISelectElement In IWebElements
ListBox1.Items.Add(ISelectElement.name & " - " & ISelectElement.id & " - " & ISelectElement.value & " - " & ISelectElement.type)
Next
'GET TEXTAREAS
IWebElements = IWebForm.getElementsByTagName("textarea")
For Each ITextAreaElement In IWebElements
ListBox1.Items.Add(ITextAreaElement.name & " - " & ITextAreaElement.id & " - " & ITextAreaElement.value & " - " & ITextAreaElement.type)
Next
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|