How to get complete html content using WatiN prope

2019-08-28 20:48发布

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

2条回答
Anthone
2楼-- · 2019-08-28 21:21

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"));
查看更多
祖国的老花朵
3楼-- · 2019-08-28 21:29

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;
}
查看更多
登录 后发表回答