访问 WatiN 中的整页源代码
作为 WatiN 测试的一部分,我正在寻找一种方法来通过 DTD 验证器传递我的网页,但我还没有找到一种访问原始 HTML 的干净方法。有内置的方法可以做到这一点吗?
我想我可以访问 IPersistStreamInit
接口的 IE.InternetExplorer
和 QueryInterface
属性,并将文档序列化为 IStream
>,但我想这似乎是一项相当常见的任务,需要做很多工作。
我在 WatiN 中遗漏了一些明显的东西吗?或者有人能想出比我上面概述的更好的解决方案吗?毕竟该解决方案是非常特定于 IE 的。
I am looking for a way to pass my webpages through a DTD validator as part of my WatiN tests, but I haven't found a clean way to access the raw HTML yet. Is there a built-in way to do it?
I think I could access the property IE.InternetExplorer
and QueryInterface
for the IPersistStreamInit
interface and serialize the document to an IStream
, but it seems like a lot of work for what I guess must be a fairly common task.
Am I missing something obvious in WatiN? Or can someone think of a better solution than the one I outlined above? That solution is very IE specific after all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
以下是访问源代码的方法:
Here is how you access the source code:
字符串 html = browser.Body.Parent.OuterHtml;
string html = browser.Body.Parent.OuterHtml;
看来没有更好的办法了。我提交了功能请求并提交而是在 WatiN 的 sourceforge 跟踪器上打一个补丁。
There doesn't appear to be a better way. I filed a feature request and submitted a patch at WatiN's sourceforge tracker instead.
我想删除一些行来帮助那些努力通过 WatiN 获取网页的原始 HTML 源代码的人,但是,无需修补 WatiN - 只是出于品味问题。
因此,利用 Johan Levin 的补丁,我将以下内容拼凑在一起。确保安全并希望您发现它有用。
Thought to drop some lines to help anyone struggling out there to get the pristine HTML source of a web page via WatiN without, however, patching WatiN - just as a matter of taste.
So capitalizing on Johan Levin's patch I bolted together the following. Be safe and hope you find it useful.
我发现:
并不总是能得到一切,因为这取决于你的“ActiveElement”,因此:
似乎工作得更好。 (
浏览器
是您的 IE 实例)尽管我相信 Johan Levin 所说的 DOM 被序列化回文本格式是正确的。
因此,通过 URL 获取文档(不使用 WatiN)来验证它不是更容易吗?
I found:
will not always get everything, as is dependant on your 'ActiveElement', Therefore:
seems to work better. (
browser
being your instance of IE)Though I believe Johan Levin is correct in saying the DOM is serialised back to text format.
Therefore would it not be easier to just fetch the document by it's URL (without using WatiN) to validate it.