Results 1 to 2 of 2

Thread: RESOLVED: MSHTML - trying to get element collection

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Resolved 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.

  2. #2

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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:
    1. Dim IWebDocument As HTMLDocument
    2.         Dim IWebForm As HTMLFormElement
    3.         Dim IInputElement As HTMLInputElement
    4.         Dim IWebElements As IHTMLElementCollection
    5.         Dim ISelectElement As HTMLSelectElement
    6.         Dim ITextAreaElement As HTMLTextAreaElement
    7.  
    8.         ListBox1.Items.Clear()
    9.  
    10.         'GET DOCUMENT
    11.         IWebDocument = CType(wb.Document, HTMLDocument)
    12.         'GET FORM
    13.         IWebForm = CType(IWebDocument.forms.item(, 0), HTMLFormElement)
    14.  
    15.         'GET INPUT ELEMENTS
    16.         IWebElements = IWebForm.getElementsByTagName("input")
    17.         For Each IInputElement In IWebElements
    18.             ListBox1.Items.Add(IInputElement.name & " - " & IInputElement.id & " - " & IInputElement.value & " - " & IInputElement.type & " - " & IInputElement.checked)
    19.         Next
    20.         'GET COMBOBOXES
    21.         IWebElements = IWebForm.getElementsByTagName("select")
    22.         For Each ISelectElement In IWebElements
    23.             ListBox1.Items.Add(ISelectElement.name & " - " & ISelectElement.id & " - " & ISelectElement.value & " - " & ISelectElement.type)
    24.         Next
    25.         'GET TEXTAREAS
    26.         IWebElements = IWebForm.getElementsByTagName("textarea")
    27.         For Each ITextAreaElement In IWebElements
    28.             ListBox1.Items.Add(ITextAreaElement.name & " - " & ITextAreaElement.id & " - " & ITextAreaElement.value & " - " & ITextAreaElement.type)
    29.         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
  •  



Click Here to Expand Forum to Full Width