Search code examples
c#.nethtmldommshtml

How to get all mshtml.IHTMLDivElement from IHTMLDocument2?


How to get all mshtml.IHTMLDivElement from IHTMLDocument2 ?

  private mshtml.IHTMLDocument2 doc = (IHTMLDocument2)WPFBrowser.Document;

  ???

  List<mshtml.IHTMLDivElement> allDivs = ???

Solution

  • I found solution. It works fantastic!

    mshtml.IHTMLDocument2 doc = (IHTMLDocument2)MainBrowser.Document;
    
    if (null != doc)
    {
         foreach (IHTMLElement element in doc.all)
         {
               if (element.id == "wrapper")
               {
                     HTMLDivElement container = element as HTMLDivElement;
    
                     dynamic dd = container;
    
                     string result = dd.IHTMLElement_innerHTML;
    
                     // You get ANY member of HTMLDivElementClass
    
                      break;
                 }
         }
    }