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.
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.
public AllFramesProcessor(HTMLDocument htmlDocument)
{
Elements = new List<INativeDocument>();
_htmlDocument = htmlDocument;
// Bug fix, trying to revert back to previous version
// http://stackoverflow.com/questions/5882415/error-when-accessing-the-frames-in-watin-new-version-2-1
//_iFrameElements = (IHTMLElementCollection)htmlDocument.all.tags("iframe");
_iFrameElements = (IHTMLElementCollection)_htmlDocument.all.tags("frame");
// If the current document doesn't contain FRAME elements, it then
// might contain IFRAME elements.
if (_iFrameElements.length == 0)
{
_iFrameElements = (IHTMLElementCollection)_htmlDocument.all.tags("iframe");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With