title: C#: possible to "convert" IHtmlElement to AutomationElement?
body: <p>I have a specific scenario where parts of an Internet Explorer are accessible through COM and IHtmlElement, but not (directly) through the GUI Tree of AutomationElements. (I have to use the tree/hierarchy to find my element. And the GUI Tree of that particular Internet Explorer is broken (don't know whether it is through customization or because it is an old version - it is a given).)</p>
  
  <p>Now there are properties of the AutomationElement that I need and cannot get off the IHtmlElement (actually, getting properties off IHtmlElement for this version of IE is broken, but getting them off AutomationElement works).</p>
  
  <p>My naive approach is to simply get the coordinates of the IHtmlElement (recursively via offsetParent), and then convert them to an AutomationElement using AutomationElement.FromPoint(x, y). This of course is not really stable (though working kind of ok).</p>
  
  <p>I tried converting through Window Handles, but.. HTMLElements seem to only possess the Window Handle of the outmost element (else websites would use up a lot of handles, I understand).</p>
  
  <p>I tried some more "fancy" approaches trying to get (again) a COM object with IID_IAccessible interface (which seems to work if I use the Main Document as a IServiceProvider), but unfortunately, i do not know later how to make an AutomationElement out of my IAccessible object (idea from <a href="https://stackoverflow.com/questions/6994469/ihtmlelement-iaccessible">IHTMLElement -&gt; IAccessible</a> ).</p>
  
  <p>Any help with this approach or my general problem as stated above is very welcome!</p>
  
  <p>Some rough code to give you an idea on my approach (though now I see that I should not use mMainDocument in the first place, but rather my current element - but this fills ae with null):</p>
  
  <pre><code>        Guid IID_IAccessible = new Guid("618736E0-3C3D-11CF-810C-00AA00389B71");
          IServiceProvider sp = (IServiceProvider)mMainDocument;
          Object ae = null;
          sp.QueryService(ref IID_IAccessible, ref IID_IAccessible, out ae);
          System.Windows.Automation.AutomationElement ae2 = System.Windows.Automation.AutomationElement.FromLocalProvider((System.Windows.Automation.Provider.IRawElementProviderSimple)ae);
          // ae is no AutomationElement, and the last line (with ae2) fails
  </code></pre>