Menu

#41 InvalidCastException in all IE Collections after AttachToIE

Version_1.0.0
closed
5
2012-09-15
2007-05-15
GoldRunner
No

I need to use IE.AttachToIE method to create IE object, attached to the opened before explorer window.

I attch to the explorer window by its' HWND, like: ie = ie = IE.AttachToIE(Find.ByCustom("hwnd", ieHwnd.ToString()));

Then, in one of my tests, I open some URL in this explorer: ie.GoTo("http://someweb/default.aspx");

After that I try to check LinksCollection on this page:

ie.Links[0] - throws exception InvalidCastException with description:

Unable to cast COM object of type 'mshtml.HTMLAnchorElementClass' to interface type 'mshtml.IHTMLElement'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3050F1FF-98B5-11CF-BB82-00AA00BDCE0B}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

at mshtml.HTMLAnchorElementClass.IHTMLElement_get_tagName()
at WatiN.Core.ElementTag.CompareTagName(IHTMLElement element)
at WatiN.Core.ElementTag.Compare(IHTMLElement element)
at WatiN.Core.ElementTag.IsValidElement(IHTMLElement element, ArrayList elementTags)
at WatiN.Core.ElementFinder.waitUntilElementReadyStateIsComplete(IHTMLElement element)
at WatiN.Core.ElementFinder.findElementsByAttribute(ElementTag elementTag, Attribute findBy, Boolean returnAfterFirstMatch)
at WatiN.Core.ElementFinder.FindAll(Attribute findBy)
at WatiN.Core.ElementFinder.FindAll()

If i just try to click by some link: ie.Link(Find.ById("gg1_buttonAdd")).Click();
at WatiN.Core.BaseElementCollection.get_Elements()

The most general operation - clicking by link (ie.Link(Find.ById("gg1_buttonAdd")).Click();) also doesn't work, because reports that "Could not find a 'A' tag containing attribute id with value 'gg1_buttonAdd'", but this link exists on the opened page...

Discussion

  • Jeroen van Menen

    Logged In: YES
    user_id=799177
    Originator: NO

    Which version of IE are you running?
    Which Windows version are you using?

    Did you run the unit test suite provided with the WatiN distribution (you need NUnit 2.2.8 to run these succesfully). All tests should pass.

     
  • Nobody/Anonymous

    Logged In: NO

    Actually I found the problem, regarding why HTML elements were not availalble - something happened with configuration of my browser, so that it failed this operation. Running this program on the other machine was sucessful. Sorry for wrong bug submitting, you may close it now.

     

Log in to post a comment.