How to get complete html content using WatiN properties

我只是一个虾纸丫 提交于 2019-12-25 03:58:31

问题


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


来源:https://stackoverflow.com/questions/7805486/how-to-get-complete-html-content-using-watin-properties

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!