Below error is thrown when accessing the ie.Frames
in new version of Watin 2.1
Error details: COM object that has been separated from its underlying RCW cannot be used.
System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, Boolean& pfNeedsRelease)
at mshtml.HTMLFrameElementClass.IHTMLElement_get_tagName()
at WatiN.Core.Native.InternetExplorer.IEElement.get_TagName()
at WatiN.Core.ElementTag.FromNativeElement(INativeElement nativeElement)
at WatiN.Core.StaticElementFinder.CreateTagList(INativeElement nativeElement)
at WatiN.Core.StaticElementFinder..ctor(DomContainer domcontainer, INativeElement nativeElement)
at WatiN.Core.Element.InitElement(DomContainer domContainer, INativeElement nativeElement, ElementFinder elementFinder)
at WatiN.Core.Element..ctor(DomContainer domContainer, INativeElement nativeElement)
at WatiN.Core.Frame..ctor(DomContainer domContainer, INativeDocument frameDocument)
at WatiN.Core.FrameCollection..ctor(DomContainer domContainer, INativeDocument htmlDocument)
at WatiN.Core.Document.get_Frames()
Please help me out it in solving this.
You can work around this by accessing
ie.NativeDocument.Frames
and then passingie
and anyINativeElement
objects to theWatiN.Core.Element
constructor:from https://sourceforge.net/tracker/?func=detail&aid=3290877&group_id=167632&atid=843727
This problem seems to be caused by the AllFramesProcessor class. The constructor for this class in Watin 1.3 looked like this:
The constructor in 2.1 looks like this:
By changing the
"htmlDocument.all.tags("iframe")"
to be"htmlDocument.all.tags("frame")"
as per the Watin 1.3 constructor this seems to resolve this issue. Not quite sure why the constructor was changed to just look for iFrames though.I modified the code for AllFramesProcessor using Praveen's suggestion (see below).
Before I did this, I did an SVN update on the Watin trunk. Jeroen made a checkin on 4/18/11 that fixed an issue around WaitForFramesToComplete to retry/wait loading the main document. Jeroen's fix alone didn't solve the problem, but I believe it's the combination of that code and the modified AllFramesProcessor that made Watin more stable around the Frames issue.
Recently I also encountered this problem and I started by following Richard Guions (accepted) answer and just to elaborate a little on that I did the following:-
and then loaded the "Watin/trunk/src/WatiN.sln" solution and recompiled the src, then referencing that new Watin.core.dll in my project.
Low and behold the
browser.Frame(Find.ByName("maincontent"));
started working and I did not need to apply any other changes to the AllFrames code. So I think that the svn source has already been updated to include this change