【问题标题】:How to get complete HTML content using WatiN properties如何使用 WatiN 属性获取完整的 HTML 内容
【发布时间】:2011-10-18 10:02:52
【问题描述】:

我在我的 ASP.NET Web 应用程序中使用 WatiN 工具。我想要我启动的 IE 的完整 HTML 内容。 WatiN 中的 IE 类提供了一个名为“Html”的属性,它只返回 HTML 源的正文内容。有什么方法可以同时获取head标签内容?

这是我的源代码:

IE myIE = new IE();
 myIE.GoTo("http://wsspg.dequecloud.com/worldspace/wsservice/eval/checkCompliance.jsp");
 myIE.TextField(Find.ByName("txtUrl")).TypeText("http://rockycode.com/blog/watin-and-xpath-support/");
 myIE.Button(Find.ByValue("Generate Report")).Click();
 myIE.WaitForComplete();
 var myHtml = myIE.Html;

【问题讨论】:

    标签: c# watin


    【解决方案1】:

    不知道为什么,但是 WatiN 不能让您直接访问 head 或 html 元素。但你仍然可以找到他们!

    using (IE myIE = new IE())
    {
        myIE.GoTo("http://wsspg.dequecloud.com/worldspace/wsservice/eval/checkCompliance.jsp");
        myIE.TextField(Find.ByName("txtUrl")).TypeText("http://rockycode.com/blog/watin-and-xpath-support/");
        myIE.Button(Find.ByValue("Generate Report")).Click();
        myIE.WaitForComplete();
        string myHtml = myIE.Body.Parent.OuterHtml;
    }
    

    【讨论】:

      【解决方案2】:

      我还没有看到完全符合您要求的任何东西,但这是您检索 head 元素的方法:-

      ElementContainer<Element> head = (ElementContainer<Element>)myIE.Element(Find.By("TagName", "HEAD"));
      

      【讨论】:

        猜你喜欢
        • 2010-09-27
        • 2012-06-04
        • 2021-12-11
        • 1970-01-01
        • 2015-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-19
        相关资源
        最近更新 更多