-->

How to get complete html content using WatiN prope

2019-08-28 20:37发布

问题:

I am using WatiN tool in my asp.net web application. I want complete html content of the IE which I had launched. IE class in WatiN provides a property called "Html" this returns only the body content of the html source. What is the way to get Head tag content also along with it. Here is my source code:

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;

Any help would be highly appreciated. Thanks

回答1:

Don't know why, but WatiN doesn't give you direct access to the head or html elements. But you can still get to them!

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:

I've not seen anything which does exactly what you want, but here's how you'd retrieve the head element:-

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