gpt4 book ai didi

c# - Watin新版本2.1访问Frames时出错

转载 作者:太空狗 更新时间:2023-10-30 00:35:03 25 4
gpt4 key购买 nike

Watin 2.1新版本访问ie.Frames报错

错误详细信息:无法使用与其底层 RCW 分离的 COM 对象。

    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()

请帮我解决这个问题。

最佳答案

我使用 Praveen 的建议修改了 AllFramesProcessor 的代码(见下文)。

在执行此操作之前,我在 Watin 主干上执行了 SVN 更新。 Jeroen 于 2011 年 4 月 18 日进行了检查,修复了 WaitForFramesToComplete 以重试/等待加载主文档的问题。仅靠 Jeroen 的修复并不能解决问题,但我相信正是该代码与修改后的 AllFramesProcessor 的结合使 Watin 在 Frames 问题上更加稳定。

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");
}
}

关于c# - Watin新版本2.1访问Frames时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5882415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com